mirror of
https://github.com/pretix/pretix.git
synced 2026-08-27 13:24:41 +00:00
Custom order emails: Allow to attach tickets and invoices
This commit is contained in:
@@ -300,6 +300,9 @@ class Invoice(models.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Invoice {} / {}>'.format(self.full_invoice_no, self.pk)
|
return '<Invoice {} / {}>'.format(self.full_invoice_no, self.pk)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.full_invoice_no
|
||||||
|
|
||||||
|
|
||||||
class InvoiceLine(models.Model):
|
class InvoiceLine(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ from pretix.base.forms.widgets import (
|
|||||||
DatePickerWidget, SplitDateTimePickerWidget,
|
DatePickerWidget, SplitDateTimePickerWidget,
|
||||||
)
|
)
|
||||||
from pretix.base.models import (
|
from pretix.base.models import (
|
||||||
InvoiceAddress, ItemAddOn, Order, OrderFee, OrderPosition, TaxRule,
|
Invoice, InvoiceAddress, ItemAddOn, Order, OrderFee, OrderPosition,
|
||||||
|
TaxRule,
|
||||||
)
|
)
|
||||||
from pretix.base.models.event import SubEvent
|
from pretix.base.models.event import SubEvent
|
||||||
from pretix.base.services.pricing import get_price
|
from pretix.base.services.pricing import get_price
|
||||||
@@ -609,6 +610,17 @@ class OrderMailForm(forms.Form):
|
|||||||
label=_("Subject"),
|
label=_("Subject"),
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
attach_tickets = forms.BooleanField(
|
||||||
|
label=_("Attach tickets"),
|
||||||
|
help_text=_("Will be ignored if all tickets in this order exceed a given size limit to ensure email deliverability."),
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
attach_invoices = forms.ModelMultipleChoiceField(
|
||||||
|
label=_("Attach invoices"),
|
||||||
|
widget=forms.CheckboxSelectMultiple,
|
||||||
|
required=False,
|
||||||
|
queryset=Invoice.objects.none()
|
||||||
|
)
|
||||||
|
|
||||||
def _set_field_placeholders(self, fn, base_parameters):
|
def _set_field_placeholders(self, fn, base_parameters):
|
||||||
phs = [
|
phs = [
|
||||||
@@ -641,6 +653,7 @@ class OrderMailForm(forms.Form):
|
|||||||
widget=forms.Textarea,
|
widget=forms.Textarea,
|
||||||
initial=order.event.settings.mail_text_order_custom_mail.localize(order.locale),
|
initial=order.event.settings.mail_text_order_custom_mail.localize(order.locale),
|
||||||
)
|
)
|
||||||
|
self.fields['attach_invoices'].queryset = order.invoices.all()
|
||||||
self._set_field_placeholders('message', ['event', 'order'])
|
self._set_field_placeholders('message', ['event', 'order'])
|
||||||
|
|
||||||
|
|
||||||
@@ -648,6 +661,7 @@ class OrderPositionMailForm(OrderMailForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
position = self.position = kwargs.pop('position')
|
position = self.position = kwargs.pop('position')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
del self.fields['attach_invoices']
|
||||||
self.fields['sendto'].initial = position.attendee_email
|
self.fields['sendto'].initial = position.attendee_email
|
||||||
self.fields['message'] = forms.CharField(
|
self.fields['message'] = forms.CharField(
|
||||||
label=_("Message"),
|
label=_("Message"),
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
{% bootstrap_field form.sendto layout='horizontal' %}
|
{% bootstrap_field form.sendto layout='horizontal' %}
|
||||||
{% bootstrap_field form.subject layout='horizontal' %}
|
{% bootstrap_field form.subject layout='horizontal' %}
|
||||||
{% bootstrap_field form.message layout='horizontal' %}
|
{% bootstrap_field form.message layout='horizontal' %}
|
||||||
|
{% bootstrap_field form.attach_tickets layout='horizontal' %}
|
||||||
|
{% if form.attach_invoices %}
|
||||||
|
{% bootstrap_field form.attach_invoices layout='horizontal' %}
|
||||||
|
{% endif %}
|
||||||
{% if request.method == "POST" %}
|
{% if request.method == "POST" %}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{% trans "E-mail preview" %}</legend>
|
<legend>{% trans "E-mail preview" %}</legend>
|
||||||
|
|||||||
@@ -1982,7 +1982,9 @@ class OrderSendMail(EventPermissionRequiredMixin, OrderViewMixin, FormView):
|
|||||||
order.send_mail(
|
order.send_mail(
|
||||||
form.cleaned_data['subject'], email_template,
|
form.cleaned_data['subject'], email_template,
|
||||||
email_context, 'pretix.event.order.email.custom_sent',
|
email_context, 'pretix.event.order.email.custom_sent',
|
||||||
self.request.user, auto_email=False
|
self.request.user, auto_email=False,
|
||||||
|
attach_tickets=form.cleaned_data.get('attach_tickets', False),
|
||||||
|
invoices=form.cleaned_data.get('attach_invoices', []),
|
||||||
)
|
)
|
||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('Your message has been queued and will be sent to {}.'.format(order.email)))
|
_('Your message has been queued and will be sent to {}.'.format(order.email)))
|
||||||
@@ -2047,7 +2049,8 @@ class OrderPositionSendMail(OrderSendMail):
|
|||||||
email_template,
|
email_template,
|
||||||
email_context,
|
email_context,
|
||||||
'pretix.event.order.position.email.custom_sent',
|
'pretix.event.order.position.email.custom_sent',
|
||||||
self.request.user
|
self.request.user,
|
||||||
|
attach_tickets=form.cleaned_data.get('attach_tickets', False),
|
||||||
)
|
)
|
||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('Your message has been queued and will be sent to {}.'.format(position.attendee_email)))
|
_('Your message has been queued and will be sent to {}.'.format(position.attendee_email)))
|
||||||
|
|||||||
Reference in New Issue
Block a user