From afc2497a48ac796e50abbbdbda45abff272f80a9 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 20 Oct 2016 13:41:25 +0200 Subject: [PATCH] [FIX] account: invoice report, advances counted twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The below revision force the use of `ABS` on the `price_subtotal_signed` because of a migration issue: 649b289fa10fcfd654a68ef6c923a07475f10296 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 --- addons/account/report/account_invoice_report.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 64a6f3f4902..012da289c02 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -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