Skip to content
Snippets Groups Projects
Commit 17465e2b authored by Brice bib Bartoletti's avatar Brice bib Bartoletti
Browse files

[FIX] stock_account:make cogs multi_company safe


Goal:
The aim of this commit is to make the cogs generation multi-company
safe.

Context:

Considering the situation in which company A has set a product P with
a real time valuation and company B didn't set the real time valuation
or has set it to manual;
Considering the user has selected both company in the switcher;
The user post an invoice for the product P.

Before this commit:
There isn't any cogs created for the invoice which is wrong.

After this commit:
Whatever the selected companies are, the cost selected will always be from
the company that created the invoice.

closes odoo/odoo#81348

Task: #2713607
Signed-off-by: default avatarLaurent Smet <las@odoo.com>
parent 9b665ba8
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ class TestAngloSaxonAccounting(AccountTestInvoicingCommon):
def setUpClass(cls):
super().setUpClass()
(cls.company_data['company'] + cls.company_data_2['company']).write({'anglo_saxon_accounting': True})
# fifo and real_time will be only set for company_A as product.category is company dependant
product_category = cls.env['product.category'].create({
'name': 'a random storable product category',
'property_cost_method': 'fifo',
......@@ -19,11 +20,6 @@ class TestAngloSaxonAccounting(AccountTestInvoicingCommon):
'type': 'product',
'categ_id': product_category.id,
})
# Those values are company dependent and need to be explicitly set for both companies
product_category.with_context(force_company=cls.company_data_2['company'].id).write({
'property_cost_method': 'fifo',
'property_valuation': 'real_time',
})
def test_cogs_should_use_price_from_the_right_company(self):
"""
......
......@@ -106,6 +106,9 @@ class AccountMove(models.Model):
'''
lines_vals_list = []
for move in self:
# Make the loop multi-company safe when accessing models like product.product
move = move.with_context(force_company=move.company_id.id)
if not move.is_sale_document(include_receipts=True) or not move.company_id.anglo_saxon_accounting:
continue
......@@ -116,11 +119,7 @@ class AccountMove(models.Model):
continue
# Retrieve accounts needed to generate the COGS.
accounts = (
line.product_id.product_tmpl_id
.with_context(force_company=line.company_id.id)
.get_product_accounts(fiscal_pos=move.fiscal_position_id)
)
accounts = line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=move.fiscal_position_id)
debit_interim_account = accounts['stock_output']
credit_expense_account = accounts['expense']
if not credit_expense_account:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment