Get invoice sequence by credit_note or invoice

When an invoice is credit note or invoice?

Actually the sequence for credit note is in case all lines, the amount is <= 0 .

But when the invoice have some lines the amount is <= 0 but other lines the amount is >=0, and the untaxed amount < 0, is or not is credit invoice?

Example:

>>> Invoice = pool.get('account.invoice')
>>> invoice = Invoice(325336)
>>> invoice.untaxed_amount
Decimal('-10.00')

At the moment, total_amount is < 0, for me, a credit note.

But, this invoice have two lines, one is > 0 and other < 0.

>>> for line in invoice.lines: line.quantity, line.amount
... 
(1.0, Decimal('10.00'))
(-1.0, Decimal('-20.00'))
>>> (all(l.amount <= 0 for l in invoice.lines if l.product) and invoice.total_amount < 0)
False

When get next number method, return “invoice” sequence and not “credit note” sequence. Is true?

1 Like

With the current implementation, and invoice is only considered as credit note when all line that have products have negative quantities.

If you have a positive product line and a negative product line, then it is considered as invoice no mather if the total amount of the invoice is negative.

A credit note could be positive or negative as an invoice, depend on the origin and the context.

But only consider a credit note when all lines are negative, it’s not correct. At least in Spain.

If we don’t want to control all the possible cases and situations to decid if is a credit note or not (I agree because will be difficult), for me the correct control will be check the total untaxed amount < 0 to decide if an invoice is a credit note or not.

It will be great if you can share the link where the normative defines the cases, so we can decide which can control. If all cases are supported by Tryton we should generate the right credit note, at least for Spain.

Please provide the complete set of official rules.