From 4c8f7c90119caa8fd0d74eb14c4b3496165d4286 Mon Sep 17 00:00:00 2001 From: yosa-odoo Date: Mon, 11 Mar 2024 15:37:51 +0100 Subject: [PATCH] [FIX] account: filters out other companies invoice analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - have two companies; Company A and Company B - create a product Product A and set a different cost in each company - create an invoice for Company A with Product A and post it - Go in invocie analysis > pivot view and set the y-axis as 'move' Issue: The invoice will be taken twice Issue: for Product A, there are two ir_property lines (one per cost/company) opw-3753395 closes odoo/odoo#157268 Signed-off-by: de Wouters de Bouchout Jean-BenoƮt (jbw) --- .../account/report/account_invoice_report.py | 1 + .../tests/test_account_invoice_report.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 342d88901f5..8bd6c7d71ec 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -132,6 +132,7 @@ class AccountInvoiceReport(models.Model): LEFT JOIN ir_property product_standard_price ON product_standard_price.res_id = CONCAT('product.product,', product.id) AND product_standard_price.name = 'standard_price' + AND product_standard_price.company_id = line.company_id JOIN {currency_table} ON currency_table.company_id = line.company_id '''.format( currency_table=self.env['res.currency']._get_query_currency_table(self.env.companies.ids, fields.Date.today()) diff --git a/addons/account/tests/test_account_invoice_report.py b/addons/account/tests/test_account_invoice_report.py index f15e1b8f814..b676fc5da69 100644 --- a/addons/account/tests/test_account_invoice_report.py +++ b/addons/account/tests/test_account_invoice_report.py @@ -120,3 +120,24 @@ class TestAccountInvoiceReport(AccountTestInvoicingCommon): [ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0 [ 600, -600, -1, 0, 800], # price_unit = 1200, currency.rate = 2.0 ]) + + def test_invoice_report_multicompany_product_cost(self): + """ + In a multicompany environment, if you define one product with different standard price per company + the invoice analysis report should only display the product from the company + Standard Price in Company A: 800 (default setup) + Standard Price in Company B: 700 + -> invoice report for Company A should remain the same + """ + self.product_a.with_company(self.company_data_2.get('company')).write({'standard_price': 700.0}) + self.assertInvoiceReportValues([ + # pylint: disable=bad-whitespace + # price_average, price_subtotal, quantity, price_margin, inventory_value + [ 2000, 2000, 1, 1200, -800], # price_unit = 6000, currency.rate = 3.0 + [ 1000, 1000, 1, 200, -800], # price_unit = 3000, currency.rate = 3.0 + [ 250, 750, 3, -1650, -2400], # price_unit = 750, currency.rate = 2.0 + [ 6, 6, 1, 0, -800], # price_unit = 12, currency.rate = 2.0 + [ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0 + [ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0 + [ 600, -600, -1, 0, 800], # price_unit = 1200, currency.rate = 2.0 + ])