From a7e0268d64c28a7662f0d2a6a663d0d8747ecd9a Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Thu, 3 Jun 2021 10:19:47 +0000 Subject: [PATCH] [FIX] account: fix Average Price measure Open Accounting>Reporting>Invoices Add measure 'Average Price' The reported amount will be wrong, as it will not consider the quantity, making an average of the price subtotal opw-2522621 closes odoo/odoo#71862 X-original-commit: 978012b38abb941c88fe85f1befa2ac659545915 Signed-off-by: Laurent Smet --- addons/account/report/account_invoice_report.py | 6 +++++- .../account/tests/test_account_invoice_report.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 4e9957c319f..e667d36a59d 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -98,7 +98,11 @@ class AccountInvoiceReport(models.Model): line.quantity / NULLIF(COALESCE(uom_line.factor, 1) / COALESCE(uom_template.factor, 1), 0.0) * (CASE WHEN move.move_type IN ('in_invoice','out_refund','in_receipt') THEN -1 ELSE 1 END) AS quantity, -line.balance * currency_table.rate AS price_subtotal, - -line.balance / NULLIF(COALESCE(uom_line.factor, 1) / COALESCE(uom_template.factor, 1), 0.0) * currency_table.rate + -COALESCE(line.balance + / NULLIF(line.quantity, 0.0) + / NULLIF(COALESCE(uom_line.factor, 1), 0.0) + / NULLIF(COALESCE(uom_template.factor, 1), 0.0), + 0.0) * currency_table.rate AS price_average, COALESCE(partner.country_id, commercial_partner.country_id) AS country_id ''' diff --git a/addons/account/tests/test_account_invoice_report.py b/addons/account/tests/test_account_invoice_report.py index 92009dd8522..1a4526cd038 100644 --- a/addons/account/tests/test_account_invoice_report.py +++ b/addons/account/tests/test_account_invoice_report.py @@ -21,7 +21,7 @@ class TestAccountInvoiceReport(AccountTestInvoicingCommon): (0, None, { 'product_id': cls.product_a.id, 'quantity': 3, - 'price_unit': 1000, + 'price_unit': 750, }), (0, None, { 'product_id': cls.product_a.id, @@ -108,11 +108,11 @@ class TestAccountInvoiceReport(AccountTestInvoicingCommon): def test_invoice_report_multiple_types(self): self.assertInvoiceReportValues([ #price_average price_subtotal quantity - [2000, 2000, 1], - [1000, 1000, 1], - [1000, 1000, 3], - [6, 6, 1], - [-20, -20, -1], - [-20, -20, -1], - [-600, -600, -1], + [2000, 2000, 1], + [1000, 1000, 1], + [250, 750, 3], + [6, 6, 1], + [-20, -20, -1], + [-20, -20, -1], + [-600, -600, -1], ])