diff --git a/product_analytic/models/account_move.py b/product_analytic/models/account_move.py index 287909fef7..e9a2750359 100644 --- a/product_analytic/models/account_move.py +++ b/product_analytic/models/account_move.py @@ -19,14 +19,13 @@ class AccountMoveLine(models.Model): @api.onchange("product_id") def _onchange_product_id(self): res = super()._onchange_product_id() - for line in self: - inv_type = line.move_id.move_type - if line.product_id and inv_type: - ana_accounts = ( - line.product_id.product_tmpl_id._get_product_analytic_accounts() - ) - ana_account = ana_accounts[INV_TYPE_MAP[inv_type]] - line.analytic_account_id = ana_account.id + inv_type = self.move_id.move_type + if self.product_id and inv_type and inv_type in INV_TYPE_MAP.keys(): + ana_accounts = ( + self.product_id.product_tmpl_id._get_product_analytic_accounts() + ) + ana_account = ana_accounts[INV_TYPE_MAP[inv_type]] + self.analytic_account_id = ana_account.id return res @api.model_create_multi @@ -35,7 +34,8 @@ def create(self, vals_list): inv_type = self.env["account.move"].browse([vals.get("move_id")]).move_type if ( vals.get("product_id") - and inv_type != "entry" + and inv_type + and inv_type in INV_TYPE_MAP.keys() and not vals.get("analytic_account_id") ): product = self.env["product.product"].browse(vals.get("product_id"))