From 017a57214388508bc704d38fc286d8a440ace19a Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Thu, 4 Nov 2021 14:38:12 +0000 Subject: [PATCH] [FIX] account : Average price fix invoice report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current behavior: Invoices report had a wrong average price when invoice had credit note Steps to reproduce: Create a db with accounting Create a customer C and a Product P Create an Invoice for C for 10 pieces of P Create a Credit note for C for 1 P Go to Reporting > Invoice Analysis Open the pivot view, in the Measures, display the Average Price, the Product quantity and the Untaxed Total The Total multiplied by the quantity is not equals to the average. opw-2557420 closes odoo/odoo#81238 X-original-commit: ef26467e288a12571c37d4c133b44f08d99cc702 Signed-off-by: William André (wan) Signed-off-by: Engels Robin (roen) --- addons/account/report/account_invoice_report.py | 2 +- addons/account/tests/test_account_invoice_report.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 05be7856475..71adc047fec 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -100,7 +100,7 @@ class AccountInvoiceReport(models.Model): -line.balance * currency_table.rate AS price_subtotal, -COALESCE( -- Average line price - (line.balance / NULLIF(line.quantity, 0.0)) + (line.balance / NULLIF(line.quantity, 0.0)) * (CASE WHEN move.move_type IN ('in_invoice','out_refund','in_receipt') THEN -1 ELSE 1 END) -- convert to template uom * (NULLIF(COALESCE(uom_line.factor, 1), 0.0) / NULLIF(COALESCE(uom_template.factor, 1), 0.0)), 0.0) * currency_table.rate AS price_average, diff --git a/addons/account/tests/test_account_invoice_report.py b/addons/account/tests/test_account_invoice_report.py index 1a4526cd038..d1458036c9d 100644 --- a/addons/account/tests/test_account_invoice_report.py +++ b/addons/account/tests/test_account_invoice_report.py @@ -103,6 +103,7 @@ class TestAccountInvoiceReport(AccountTestInvoicingCommon): 'price_subtotal': vals[1], 'quantity': vals[2], } for vals in expected_values_list] + self.assertRecordValues(reports, expected_values_dict) def test_invoice_report_multiple_types(self): @@ -112,7 +113,7 @@ class TestAccountInvoiceReport(AccountTestInvoicingCommon): [1000, 1000, 1], [250, 750, 3], [6, 6, 1], - [-20, -20, -1], - [-20, -20, -1], - [-600, -600, -1], + [20, -20, -1], + [20, -20, -1], + [600, -600, -1], ])