[FIX] account: invoice report, advances counted twice
The below revision force the use of `ABS` on the
`price_subtotal_signed` because of a migration issue:
649b289fa1
This leads to issues regarding the advances, in
`out_invoice` invoices, where this amount
`price_subtotal_signed` is negative, and should
remain negative in this report, otherwise
the advance is counted twice: Once with
the advance invoice, and a second in the actual
invoice where the advance is removed with a line
with a negative `price_subtotal`
e.g.
- A sale order of 500€ without taxes
- Create an advance invoice for an advance payment of 10%: 50€ without taxes
- A second invoice with the remaining: 450€ without taxes
In the invoices report, the total without taxes for this customer was
displayed as 600€ (50 + 500 + 50)
instead of 500€ (50 + 500 - 50)
opw-682390
This commit is contained in:
@@ -115,11 +115,17 @@ class AccountInvoiceReport(models.Model):
|
||||
THEN (- ail.quantity) / u.factor * u2.factor
|
||||
ELSE ail.quantity / u.factor * u2.factor
|
||||
END) AS product_qty,
|
||||
SUM(ABS(ail.price_subtotal_signed) * CASE
|
||||
WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text])
|
||||
THEN -1
|
||||
ELSE 1
|
||||
END
|
||||
SUM(ABS(ail.price_subtotal_signed)
|
||||
* CASE
|
||||
WHEN ail.price_subtotal < 0
|
||||
THEN -1
|
||||
ELSE 1
|
||||
END
|
||||
* CASE
|
||||
WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text])
|
||||
THEN -1
|
||||
ELSE 1
|
||||
END
|
||||
) AS price_total,
|
||||
SUM(ABS(ail.price_subtotal_signed)) / CASE
|
||||
WHEN SUM(ail.quantity / u.factor * u2.factor) <> 0::numeric
|
||||
|
||||
Reference in New Issue
Block a user