[FIX] account: filters out other companies invoice analysis

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) <jbw@odoo.com>
This commit is contained in:
yosa-odoo
2024-03-12 10:34:54 +00:00
parent 5ed04d06c2
commit 4c8f7c9011
2 changed files with 22 additions and 0 deletions
@@ -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())
@@ -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
])