From ee2cb8d1e612ee79a19e7d232316cb085ef8165c Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Mon, 7 Feb 2022 16:17:57 +0000 Subject: [PATCH] [FIX] mrp: prevent traceback when choosing a BOM of a product without a variant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Go to inventory > configuration > Products > Attributes - Create a new Dynamic Attributes > add two attribute values - Create a storable Product “Test”: - Add the two attributes - Save - Create a BOM related to this product - Create a new manufacturing order: - Do not choose a product - Select the BOM related to the product “test” Problem: Traceback is triggered because as the product template only has dynamic variants, there is not a `product.product` record created yet. but we try to access it in the onchange: https://github.com/odoo/odoo/blob/14.0/addons/mrp/models/mrp_production.py#L598 Solution: do not set the product when a BOM of a product_tmpl without a variant was chosen opw-2732254 closes odoo/odoo#84543 X-original-commit: 50b538e7d32bbce7cad7c05f0bc80db6b969a70b Signed-off-by: Arnold Moyaux Signed-off-by: Djamel Touati (otd) --- addons/mrp/models/mrp_production.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index cd8adbb2984..52254b25b82 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -639,7 +639,7 @@ class MrpProduction(models.Model): @api.onchange('bom_id') def _onchange_bom_id(self): if not self.product_id and self.bom_id: - self.product_id = self.bom_id.product_id or self.bom_id.product_tmpl_id.product_variant_ids[0] + self.product_id = self.bom_id.product_id or self.bom_id.product_tmpl_id.product_variant_ids[:1] self.product_qty = self.bom_id.product_qty or 1.0 self.product_uom_id = self.bom_id and self.bom_id.product_uom_id.id or self.product_id.uom_id.id self.move_raw_ids = [(2, move.id) for move in self.move_raw_ids.filtered(lambda m: m.bom_line_id)]