From 0fe86d4b4061b0bc1be713a7bed1850c9aadb11f Mon Sep 17 00:00:00 2001 From: "Florimond Husquinet (fhu)" Date: Thu, 5 Sep 2019 06:52:39 +0000 Subject: [PATCH] [FIX] mrp_bom_cost: compute price from bom ensure one fail - Activate mrp bom cost. - Create a BoM for a product - The Compute "Price from BoM" button appear on the product template below the Cost field. - Click the button. Before this commit: Probably because dynamic variant creation is activated and there is no variants, the ensure_one fails with 0 records actually passed to the function. Additionally, if all the BoM are for variants and there is no BoM for the template, then there is a division by 0 exception. After this commit: A test is performed to avoid calling the function with 0 records. A test is performed to avoid a division by 0 exception. closes odoo/odoo#36761 Opw: 2064884 X-original-commit: 42264002070c8acbb781bd111d8a0c31e2ad9716 Signed-off-by: Nicolas Martinelli (nim) --- addons/mrp_bom_cost/models/product.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mrp_bom_cost/models/product.py b/addons/mrp_bom_cost/models/product.py index fc0f56be631..da15e757cb3 100644 --- a/addons/mrp_bom_cost/models/product.py +++ b/addons/mrp_bom_cost/models/product.py @@ -11,11 +11,13 @@ class ProductTemplate(models.Model): def action_bom_cost(self): templates = self.filtered(lambda t: t.product_variant_count == 1 and t.bom_count > 0) - return templates.mapped('product_variant_id').action_bom_cost() + if templates: + return templates.mapped('product_variant_id').action_bom_cost() def button_bom_cost(self): templates = self.filtered(lambda t: t.product_variant_count == 1 and t.bom_count > 0) - return templates.mapped('product_variant_id').button_bom_cost() + if templates: + return templates.mapped('product_variant_id').button_bom_cost() class ProductProduct(models.Model):