diff --git a/src/pretix/base/migrations/0198_invoice_sent_to_customer.py b/src/pretix/base/migrations/0198_invoice_sent_to_customer.py new file mode 100644 index 0000000000..a82a362f59 --- /dev/null +++ b/src/pretix/base/migrations/0198_invoice_sent_to_customer.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.4 on 2021-09-30 10:25 +from datetime import datetime + +from django.db import migrations, models +from pytz import UTC + + +class Migration(migrations.Migration): + + dependencies = [ + ('pretixbase', '0197_auto_20210914_0814'), + ] + + operations = [ + migrations.AddField( + model_name='invoice', + name='sent_to_customer', + field=models.DateTimeField(blank=True, null=True, default=UTC.localize(datetime(1970, 1, 1, 0, 0, 0, 0))), + preserve_default=False, + ), + ] diff --git a/src/pretix/base/models/invoices.py b/src/pretix/base/models/invoices.py index a4344cea11..54cf70fd7f 100644 --- a/src/pretix/base/models/invoices.py +++ b/src/pretix/base/models/invoices.py @@ -159,6 +159,8 @@ class Invoice(models.Model): # False: The invoice wasn't sent and never will, because sending was not configured at the time of the check. sent_to_organizer = models.BooleanField(null=True, blank=True) + sent_to_customer = models.DateTimeField(null=True, blank=True) + file = models.FileField(null=True, blank=True, upload_to=invoice_filename, max_length=255) objects = ScopedManager(organizer='event__organizer') diff --git a/src/pretix/base/services/invoices.py b/src/pretix/base/services/invoices.py index c0c49c8357..7de971b41e 100644 --- a/src/pretix/base/services/invoices.py +++ b/src/pretix/base/services/invoices.py @@ -291,6 +291,7 @@ def generate_cancellation(invoice: Invoice, trigger_pdf=True): cancellation.payment_provider_text = '' cancellation.file = None cancellation.sent_to_organizer = None + cancellation.sent_to_customer = None with language(invoice.locale, invoice.event.settings.region): cancellation.invoice_from = invoice.event.settings.get('invoice_address_from') cancellation.invoice_from_name = invoice.event.settings.get('invoice_address_from_name') @@ -346,8 +347,8 @@ def invoice_pdf_task(invoice: int): i.file.delete() with language(i.locale, i.event.settings.region): fname, ftype, fcontent = i.event.invoice_renderer.generate(i) - i.file.save(fname, ContentFile(fcontent)) - i.save() + i.file.save(fname, ContentFile(fcontent), save=False) + i.save(update_fields=['file']) return i.file.name diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 82360f45b0..02d2be1ac9 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -57,7 +57,7 @@ from django.core.mail import ( from django.core.mail.message import SafeMIMEText from django.db import transaction from django.template.loader import get_template -from django.utils.timezone import override +from django.utils.timezone import now, override from django.utils.translation import gettext as _, pgettext from django_scopes import scope, scopes_disabled from i18nfield.strings import LazyI18nString @@ -438,6 +438,7 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st email = email_filter.send_chained(event, 'message', message=email, order=order, user=user) + invoices_sent = [] if invoices: invoices = Invoice.objects.filter(pk__in=invoices) for inv in invoices: @@ -449,6 +450,7 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st inv.file.file.read(), 'application/pdf' ) + invoices_sent.append(inv) except: logger.exception('Could not attach invoice to email') pass @@ -558,6 +560,10 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st ) logger.exception('Error sending email') raise SendMailException('Failed to send an email to {}.'.format(to)) + else: + for i in invoices_sent: + i.sent_to_customer = now() + i.save(update_fields=['sent_to_customer']) def mail_send(*args, **kwargs): diff --git a/src/pretix/control/templates/pretixcontrol/order/index.html b/src/pretix/control/templates/pretixcontrol/order/index.html index 9739df9578..2dece2d272 100644 --- a/src/pretix/control/templates/pretixcontrol/order/index.html +++ b/src/pretix/control/templates/pretixcontrol/order/index.html @@ -234,7 +234,23 @@ {% for i in invoices %} {% if i.is_cancellation %}{% trans "Cancellation" context "invoice" %}{% else %}{% trans "Invoice" %}{% endif %} - {{ i.number }} ({{ i.date|date:"SHORT_DATE_FORMAT" }}) + {{ i.number }} + ({{ i.date|date:"SHORT_DATE_FORMAT" }}) + {% if i.sent_to_customer.year == 1970 %} + + + + + {% elif i.sent_to_customer %} + + + + + {% else %} + + + + {% endif %} {% if not i.canceled %} {% if request.event.settings.invoice_regenerate_allowed %}
{% endif %} {% endfor %} + {% if invoices_send_link %} +