mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Allow to use datetime components in invoice prefixes (#1529)
This commit is contained in:
@@ -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-'
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user