diff --git a/addons/purchase_mrp/models/mrp_bom.py b/addons/purchase_mrp/models/mrp_bom.py index dfa662b8b35..0190cef0a66 100644 --- a/addons/purchase_mrp/models/mrp_bom.py +++ b/addons/purchase_mrp/models/mrp_bom.py @@ -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