changeset 0405b129e759 in modules/account_invoice:default
details:
https://hg.tryton.org/modules/account_invoice?cmd=changeset;node=0405b129e759
description:
Extract sequence field computation from get_next_number
This eases the customization of the sequence used.
issue9038
review270931002
diffstat:
invoice.py | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diffs (40 lines):
diff -r c174fe563e2b -r 0405b129e759 invoice.py
--- a/invoice.py Wed Mar 04 10:24:45 2020 +0100
+++ b/invoice.py Fri Mar 06 23:50:37 2020 +0100
@@ -1047,17 +1047,11 @@
pattern.setdefault('company', self.company.id)
pattern.setdefault('fiscalyear', fiscalyear.id)
pattern.setdefault('period', period.id)
- invoice_type = self.type
- if (all(l.amount <= 0 for l in self.lines if l.product)
- and self.total_amount < 0):
- invoice_type += '_credit_note'
- else:
- invoice_type += '_invoice'
for invoice_sequence in fiscalyear.invoice_sequences:
if invoice_sequence.match(pattern):
sequence = getattr(
- invoice_sequence, '%s_sequence' % invoice_type)
+ invoice_sequence, self._sequence_field)
break
else:
raise InvoiceNumberError(
@@ -1067,6 +1061,17 @@
with Transaction().set_context(date=accounting_date):
return Sequence.get_id(sequence.id), sequence
+ @property
+ def _sequence_field(self):
+ "Returns the field name of invoice_sequence to use"
+ field = self.type
+ if (all(l.amount <= 0 for l in self.lines if l.product)
+ and self.total_amount < 0):
+ field += '_credit_note'
+ else:
+ field += '_invoice'
+ return field + '_sequence'
+
@classmethod
def tax_identifier_types(cls):
return Pool().get('party.party').tax_identifier_types()