diff -r 6c85f394741c invoice.py --- a/trytond/trytond/modules/account_invoice/invoice.py Wed Jan 24 20:14:28 2018 +0100 +++ b/trytond/trytond/modules/account_invoice/invoice.py Wed Feb 07 15:39:49 2018 +0100 @@ -1020,6 +1020,11 @@ 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') @@ -1040,11 +1045,7 @@ 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):