mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Allow to change length of invoice numbers
This commit is contained in:
@@ -597,6 +597,7 @@ class EventSettingsSerializer(serializers.Serializer):
|
||||
'invoice_numbers_consecutive',
|
||||
'invoice_numbers_prefix',
|
||||
'invoice_numbers_prefix_cancellations',
|
||||
'invoice_numbers_counter_length',
|
||||
'invoice_attendee_name',
|
||||
'invoice_include_expire_date',
|
||||
'invoice_address_explanation_text',
|
||||
|
||||
@@ -116,8 +116,8 @@ class Invoice(models.Model):
|
||||
objects = ScopedManager(organizer='event__organizer')
|
||||
|
||||
@staticmethod
|
||||
def _to_numeric_invoice_number(number):
|
||||
return '{:05d}'.format(int(number))
|
||||
def _to_numeric_invoice_number(number, places):
|
||||
return ('{:0%dd}' % places).format(int(number))
|
||||
|
||||
@property
|
||||
def full_invoice_from(self):
|
||||
@@ -173,7 +173,7 @@ class Invoice(models.Model):
|
||||
]
|
||||
return '\n'.join([p.strip() for p in parts if p and p.strip()])
|
||||
|
||||
def _get_numeric_invoice_number(self):
|
||||
def _get_numeric_invoice_number(self, c_length):
|
||||
numeric_invoices = Invoice.objects.filter(
|
||||
event__organizer=self.event.organizer,
|
||||
prefix=self.prefix,
|
||||
@@ -182,7 +182,7 @@ class Invoice(models.Model):
|
||||
).aggregate(
|
||||
max=Max('numeric_number')
|
||||
)['max'] or 0
|
||||
return self._to_numeric_invoice_number(numeric_invoices + 1)
|
||||
return self._to_numeric_invoice_number(numeric_invoices + 1, c_length)
|
||||
|
||||
def _get_invoice_number_from_order(self):
|
||||
return '{order}-{count}'.format(
|
||||
@@ -209,7 +209,7 @@ class Invoice(models.Model):
|
||||
self.prefix += 'TEST-'
|
||||
for i in range(10):
|
||||
if self.event.settings.get('invoice_numbers_consecutive'):
|
||||
self.invoice_no = self._get_numeric_invoice_number()
|
||||
self.invoice_no = self._get_numeric_invoice_number(self.event.settings.invoice_numbers_counter_length)
|
||||
else:
|
||||
self.invoice_no = self._get_invoice_number_from_order()
|
||||
try:
|
||||
|
||||
@@ -309,6 +309,16 @@ DEFAULTS = {
|
||||
help_text=_("The expiration date will not be shown if the invoice is generated after the order is paid."),
|
||||
)
|
||||
},
|
||||
'invoice_numbers_counter_length': {
|
||||
'default': '5',
|
||||
'type': int,
|
||||
'form_class': forms.IntegerField,
|
||||
'serializer_class': serializers.IntegerField,
|
||||
'form_kwargs': dict(
|
||||
label=_("Minimum length of invoice number after prefix"),
|
||||
help_text=_("The part of your invoice number after your prefix will be filled up with leading zeros up to this length, e.g. INV-001 or INV-00001."),
|
||||
)
|
||||
},
|
||||
'invoice_numbers_consecutive': {
|
||||
'default': 'True',
|
||||
'type': bool,
|
||||
|
||||
@@ -677,6 +677,7 @@ class InvoiceSettingsForm(SettingsForm):
|
||||
'invoice_numbers_consecutive',
|
||||
'invoice_numbers_prefix',
|
||||
'invoice_numbers_prefix_cancellations',
|
||||
'invoice_numbers_counter_length',
|
||||
'invoice_address_explanation_text',
|
||||
'invoice_email_attachment',
|
||||
'invoice_address_from_name',
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
{% bootstrap_field form.invoice_numbers_consecutive layout="control" %}
|
||||
{% bootstrap_field form.invoice_numbers_prefix layout="control" %}
|
||||
{% bootstrap_field form.invoice_numbers_prefix_cancellations layout="control" %}
|
||||
{% bootstrap_field form.invoice_numbers_counter_length layout="control" %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{% trans "Address form" %}</legend>
|
||||
|
||||
Reference in New Issue
Block a user