diff --git a/src/pretix/base/models/invoices.py b/src/pretix/base/models/invoices.py index 145e5bb047..c5cd067dd0 100644 --- a/src/pretix/base/models/invoices.py +++ b/src/pretix/base/models/invoices.py @@ -191,6 +191,9 @@ class Invoice(models.Model): self.prefix = self.event.settings.invoice_numbers_prefix or (self.event.slug.upper() + '-') if self.is_cancellation: self.prefix = self.event.settings.invoice_numbers_prefix_cancellations or self.prefix + if '%' in self.prefix: + self.prefix = self.date.strftime(self.prefix) + if not self.invoice_no: if self.order.testmode: self.prefix += 'TEST-' diff --git a/src/pretix/control/forms/event.py b/src/pretix/control/forms/event.py index 15a9d3bd9a..7b560d0ddf 100644 --- a/src/pretix/control/forms/event.py +++ b/src/pretix/control/forms/event.py @@ -844,7 +844,9 @@ class InvoiceSettingsForm(SettingsForm): help_text=_("This will be prepended to invoice numbers. If you leave this field empty, your event slug will " "be used followed by a dash. Attention: If multiple events within the same organization use the " "same value in this field, they will share their number range, i.e. every full number will be " - "used at most once over all of your events. This setting only affects future invoices."), + "used at most once over all of your events. This setting only affects future invoices. You can " + "use %Y (with century) %y (without century) to insert the year of the invoice, or %m and %d for " + "the day of month."), required=False, ) invoice_numbers_prefix_cancellations = forms.CharField( diff --git a/src/tests/base/test_invoices.py b/src/tests/base/test_invoices.py index 83211bcebe..d7b15be0c2 100644 --- a/src/tests/base/test_invoices.py +++ b/src/tests/base/test_invoices.py @@ -419,6 +419,10 @@ def test_invoice_number_prefixes(env): assert i.number == 'inv_00001' assert generate_cancellation(i).number == 'crd_00001' + event2.settings.set('invoice_numbers_prefix', 'inv_%Y%m%d_') + i = generate_invoice(order2) + assert i.number == 'inv_%s_00001' % now().date().strftime('%Y%m%d') + # Test database uniqueness check with pytest.raises(DatabaseError): with transaction.atomic():