[FIX] purchase_mrp: constrains not working

before this commit, in BoM form view, it was allowing to select BoM product as the BoM line product , as the constrains decorator was missing in this inherited function. typo in field name

after this commit, it is not allowed to add BoM product as BoM line product, as it will show the UserError. instead of bom_lines bom_line_ids used

closes odoo/odoo#111416

X-original-commit: 6e68005b27613ce84fe54d6d2f9273aa3ccfd662
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
mehjabinfarsana
2023-01-31 15:17:52 +01:00
parent b8e8e7de8e
commit 500c555690
+5 -4
View File
@@ -1,21 +1,22 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class MrpBom(models.Model):
_inherit = 'mrp.bom'
@api.constrains('product_id', 'product_tmpl_id', 'bom_line_ids', 'byproduct_ids', 'operation_ids')
def _check_bom_lines(self):
res = super()._check_bom_lines()
for bom in self:
if all(not bl.cost_share for bl in bom.bom_lines):
if all(not bl.cost_share for bl in bom.bom_line_ids):
continue
if any(bl.cost_share < 0 for bl in bom.bom_lines):
if any(bl.cost_share < 0 for bl in bom.bom_line_ids):
raise UserError(_("Components cost share have to be positive or equals to zero."))
if sum(bom.bom_lines.mapped('cost_share')) != 100:
if sum(bom.bom_line_ids.mapped('cost_share')) != 100:
raise UserError(_("The total cost share for a BoM's component have to be 100"))
return res