diff options
| author | Nicolas Galler <ngl@odoo.com> | 2020-10-05 17:26:49 +0000 |
|---|---|---|
| committer | Nicolas Galler <ngl@odoo.com> | 2020-10-08 15:45:03 +0000 |
| commit | 917e4c67b4aa14ca71ec6cba4bc6d20a86459f42 (patch) | |
| tree | 4835ecf60ce6548e9db8bed3be832ad01647aa27 /addons/mrp/models/mrp_bom.py | |
| parent | 000af2688e32d19b1874df2e909ccf0ddf636b91 (diff) | |
[FIX] mrp: validate BOM lines with same product as BOM
Current behavior before PR:
It is possible to create a BOM that has a BOM line that reference the
same product as the BOM itself. This is undesirable as when we create a
manufacturing order for this product we will have an error.
It is a regression bug that was introduced in commit
575353e251a0cce3bbff759edaeb56b5718beb11 between v12 and v13.
Behavior after PR is merged:
When saving a BOM it will validate that no product line references the
same product, or the same product variant, as the BOM itself. Note that
it is allowed to have a BOM for a product variant that references
another variant of the same product.
opw-2347941
closes odoo/odoo#59485
X-original-commit: 881596f
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons/mrp/models/mrp_bom.py')
| -rw-r--r-- | addons/mrp/models/mrp_bom.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index b21998d3cc2..fc01dfb1ade 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -89,8 +89,12 @@ class MrpBom(models.Model): def _check_bom_lines(self): for bom in self: for bom_line in bom.bom_line_ids: - if bom.product_id and bom_line.product_id == bom.product_id: - raise ValidationError(_("BoM line product %s should not be the same as BoM product.", bom.display_name)) + if bom.product_id: + same_product = bom.product_id == bom_line.product_id + else: + same_product = bom.product_tmpl_id == bom_line.product_id.product_tmpl_id + if same_product: + raise ValidationError(_("BoM line product %s should not be the same as BoM product.") % bom.display_name) if bom.product_id and bom_line.bom_product_template_attribute_value_ids: raise ValidationError(_("BoM cannot concern product %s and have a line with attributes (%s) at the same time.") % (bom.product_id.display_name, ", ".join([ptav.display_name for ptav in bom_line.bom_product_template_attribute_value_ids]))) |
