[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) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-06-17 16:03:26 +00:00
parent 56c96e9418
commit fac71123c5
+5 -1
View File
@@ -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: