[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) <nim@odoo.com>
This commit is contained in:
Florimond Husquinet (fhu)
2019-09-12 09:39:23 +00:00
committed by fw-bot
parent 26c62cbb44
commit 0fe86d4b40
+4 -2
View File
@@ -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):