From d48da27e641cfaf86a7f2535a6a2de3bf8d9006e Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 17 May 2019 11:13:17 +0000 Subject: [PATCH] [FIX] account: Invoice Analysis total without sign - Go to Accounting > Reports > Invoices - Go to the pivot view - Enable 'Total' and 'Untaxed Total' in the measures The Total is wrong. The sign of the total must be positive for the customer invoices and the vendors refunds; and negative for the credit notes and the vendors bills. Before this commit, the total of the credit notes and the vendors bills weren't negative. This occurs because the sign of the result of amount_total * invoice_type.sign is different of the sign of amount_total_signed. Indeed amount_total is the total amount without sign, and invoice_type.sign is used to change the sign only for the vendors bills and the vendors refunds (see https://github.com/odoo/odoo/blob/3cf9cfc985950c30c6b76480f77f5ffe53650b24/addons/account/report/account_invoice_report.py#L144). Contrariwise amount_total_signed is the total amount signed : negative for the credit notes and the vendors refunds. Later on the calculation, the total amount is multiplied to invoice_type.sign, to have the signs as expected (see https://github.com/odoo/odoo/blob/3cf9cfc985950c30c6b76480f77f5ffe53650b24/addons/account/report/account_invoice_report.py#L118) Fine tuning of this commit: 4218f3b opw-1999175 --- addons/account/report/account_invoice_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 7861644525a..99b79387eb7 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -114,7 +114,7 @@ class AccountInvoiceReport(models.Model): ai.partner_bank_id, SUM ((invoice_type.sign_qty * ail.quantity) / u.factor * u2.factor) AS product_qty, SUM(ail.price_subtotal_signed * invoice_type.sign) AS price_total, - (ai.amount_total * invoice_type.sign) / (SELECT count(*) FROM account_invoice_line l where invoice_id = ai.id) * + ai.amount_total_signed / (SELECT count(*) FROM account_invoice_line l where invoice_id = ai.id) * count(*) * invoice_type.sign AS amount_total, SUM(ABS(ail.price_subtotal_signed)) / CASE WHEN SUM(ail.quantity / u.factor * u2.factor) <> 0::numeric