diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index c33cb6ee469..aa33b41d94f 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -360,6 +360,13 @@ msgstr "" msgid "A Manufacturing Order is already done or cancelled." msgstr "" +#. module: mrp +#: code:addons/mrp/models/stock_warehouse.py:0 +#, python-format +msgid "" +"A product with a kit-type bill of materials can not have a reordering rule." +msgstr "" + #. module: mrp #: model:ir.model.fields,field_description:mrp.field_mrp_document__access_token msgid "Access Token" @@ -4795,6 +4802,14 @@ msgid "" "link to your file." msgstr "" +#. module: mrp +#: code:addons/mrp/models/mrp_bom.py:0 +#, python-format +msgid "" +"You can not create a kit-type bill of materials for products that have at " +"least one reordering rule." +msgstr "" + #. module: mrp #: code:addons/mrp/models/mrp_bom.py:0 #, python-format diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index b4789826062..7f67e94fd2f 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -145,6 +145,13 @@ class MrpBom(models.Model): def name_get(self): return [(bom.id, '%s%s' % (bom.code and '%s: ' % bom.code or '', bom.product_tmpl_id.display_name)) for bom in self] + @api.constrains('product_tmpl_id', 'product_id', 'type') + def check_kit_has_not_orderpoint(self): + product_ids = [pid for bom in self.filtered(lambda bom: bom.type == "phantom") + for pid in (bom.product_id.ids or bom.product_tmpl_id.product_variant_ids.ids)] + if self.env['stock.warehouse.orderpoint'].search([('product_id', 'in', product_ids)], count=True): + raise ValidationError(_("You can not create a kit-type bill of materials for products that have at least one reordering rule.")) + @api.ondelete(at_uninstall=False) def _unlink_except_running_mo(self): if self.env['mrp.production'].search([('bom_id', 'in', self.ids), ('state', 'not in', ['done', 'cancel'])], limit=1): diff --git a/addons/mrp/models/stock_warehouse.py b/addons/mrp/models/stock_warehouse.py index ae630ee961c..2a99d181cd4 100644 --- a/addons/mrp/models/stock_warehouse.py +++ b/addons/mrp/models/stock_warehouse.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models, _ -from odoo.exceptions import UserError +from odoo.exceptions import ValidationError, UserError class StockWarehouse(models.Model): @@ -296,3 +296,13 @@ class StockWarehouse(models.Model): if warehouse.manufacture_pull_id and name: warehouse.manufacture_pull_id.write({'name': warehouse.manufacture_pull_id.name.replace(warehouse.name, name, 1)}) return res + +class Orderpoint(models.Model): + _inherit = "stock.warehouse.orderpoint" + + @api.constrains('product_id') + def check_product_is_not_kit(self): + if self.env['mrp.bom'].search(['|', ('product_id', 'in', self.product_id.ids), + '&', ('product_id', '=', False), ('product_tmpl_id', 'in', self.product_id.product_tmpl_id.ids), + ('type', '=', 'phantom')], count=True): + raise ValidationError(_("A product with a kit-type bill of materials can not have a reordering rule."))