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.

In accounting, distinguishing between an invoice and a credit note can sometimes be complex, especially when dealing with mixed line amounts. Based on your example, hereā€™s a detailed explanation:
Understanding Credit Notes and Invoices:

Credit Note Definition:
A credit note is typically issued to correct an invoice error or to provide a reduction in the amount owed by the customer. It usually has a negative total amount.

Invoice with Mixed Line Amounts:
When an [invoice](https://sleekbill.in) contains both positive and negative line amounts, the determination of whether it is an invoice or a credit note depends on the total amount.

Example Analysis:

Invoice Total Amount: Decimal('-10.00')
    This indicates that overall, the customer is owed money back.

Line Items:
    Line 1: (1.0, Decimal('10.00')) - Positive amount.
    Line 2: (-1.0, Decimal('-20.00')) - Negative amount.

Given the total amount (-10.00), the document appears to be a credit note because it signifies a net refund to the customer.

However, the condition (all(l.amount <= 0 for l in invoice.lines if l.product) and invoice.total_amount < 0) evaluates to False because not all line amounts are <= 0.
Proper Classification:

Credit Note:
    If the untaxed_amount and total_amount are both < 0, the document should be considered a credit note, regardless of mixed line amounts.
Invoice:
    If the untaxed_amount and total_amount are both >= 0, it is an invoice.

Handling Mixed Amounts:

When an invoice contains mixed line amounts (positive and negative), but the total amount is negative, it should logically be classified as a credit note due to the overall refund to the customer.
Next Number Method:

The method for determining the next number sequence should account for the total amount:

If invoice.total_amount < 0, the next number should follow the "credit note" sequence.
If invoice.total_amount >= 0, the next number should follow the "invoice" sequence.

Final Determination:

Based on the provided example, your invoice with an untaxed_amount of -10.00 and mixed line amounts should be classified as a credit note, as the total amount is negative.

python

Invoice = pool.get(ā€˜account.invoiceā€™)
invoice = Invoice(325336)
invoice.untaxed_amount
Decimal(ā€˜-10.00ā€™)
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

Correct Classification

invoice.is_credit_note = invoice.total_amount < 0

This adjustment ensures accurate classification and sequence assignment based on the total amount.