trytond-patches/issue6253.diff

30 lines
1.2 KiB
Diff

diff --git a/invoice.py b/invoice.py
index e58e444..5d44cd7 100644
--- a/trytond/trytond/modules/account_invoice/invoice.py
+++ b/trytond/trytond/modules/account_invoice/invoice.py
@@ -992,6 +992,11 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
invoice.number = invoice.get_next_number()
cls.save(invoices)
+ def invoice_type_criteria(self):
+ if self.untaxed_amount < 0:
+ return '_credit_note'
+ return '_invoice'
+
def get_next_number(self, pattern=None):
pool = Pool()
Sequence = pool.get('ir.sequence.strict')
@@ -1013,11 +1018,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
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'
+ invoice_type += self.invoice_type_criteria()
for invoice_sequence in fiscalyear.invoice_sequences:
if invoice_sequence.match(pattern):