Skip to content

Commit

Permalink
[FIX] account: invoice report, advances counted twice
Browse files Browse the repository at this point in the history
The below revision force the use of `ABS` on the
`price_subtotal_signed` because of a migration issue:
649b289

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
  • Loading branch information
beledouxdenis committed Oct 20, 2016
1 parent e69b0d9 commit afc2497
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions addons/account/report/account_invoice_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ def _sub_select(self):
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
Expand Down

0 comments on commit afc2497

Please sign in to comment.