From fac71123c576e7d7049c077f016dbf6e7fa49f00 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 17 Jun 2020 12:42:41 +0000 Subject: [PATCH] [FIX] stock_account: company of anglo-saxon AML - Create 2 companies A & B - Create a product with automatic valuation - Switch to company A - Create a SO for 1 unit of the product, validate and deliver - Genrerate the invoice - Switch to company B, but keep company A allowed - Post the invoice An error is raised because of inconsistent company: > Some records are incompatible with the company... This occurs because the anglo-saxon lines are created in accounts belonging to company B instead of company A. Since the product accounts are property fields, using `force_company` in the context allows the selection of the right accounts. opw-2276657 closes odoo/odoo#53183 X-original-commit: 603ce0f408a4479324a0905f5bc569c9f08567dd Signed-off-by: Nicolas Martinelli (nim) --- addons/stock_account/models/account_move.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index 62efdf8f4b0..e3ffb4ce05d 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -103,7 +103,11 @@ class AccountMove(models.Model): continue # Retrieve accounts needed to generate the COGS. - accounts = line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=move.fiscal_position_id) + accounts = ( + line.product_id.product_tmpl_id + .with_company(line.company_id) + .get_product_accounts(fiscal_pos=move.fiscal_position_id) + ) debit_interim_account = accounts['stock_output'] credit_expense_account = accounts['expense'] if not debit_interim_account or not credit_expense_account: