From ca744428ef55a6638f7b4697f96b8197f11a26ed Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 12 Aug 2021 13:31:37 +0100 Subject: [PATCH] [FIX] account_asset_management: make asset company match move's To start, the context `company_id` is no longer used in v14. Instead, we use `with_company`. OTOH, it doesn't make much sense because in case you have several companies enabled in your context, not necessarily your main one is gonna be the one that should be used for the asset. Instead, it should be the move company always, or consistency rules will fail. Altered forward port of https://github.com/OCA/account-financial-tools/pull/1223. @Tecnativa TT31311 --- account_asset_management/models/account_move.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index f70f226ba..34a13a969 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -79,14 +79,10 @@ class AccountMove(models.Model): "date_start": move.date, "account_analytic_id": aml.analytic_account_id, } - if self.env.context.get("company_id"): - vals["company_id"] = self.env["res.company"].browse( - self.env.context["company_id"] - ) asset_form = Form( - self.env["account.asset"].with_context( - create_asset_from_move_line=True, move_id=move.id - ) + self.env["account.asset"] + .with_company(move.company_id) + .with_context(create_asset_from_move_line=True, move_id=move.id) ) for key, val in vals.items(): setattr(asset_form, key, val)