From 3892e472f7f82bd43753ef246fb000c15af4b2f6 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Fri, 18 Mar 2022 10:41:13 +0000 Subject: [PATCH] [FIX] mrp: prevent MO creation with the same component as product to produce MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product “P1” - Add a BOM - Try to add the product P1 as a component > save > validation error is triggered > it's not possible to add the same component as the product to produce > correct behavior - Create a manufacturing order: - Select the product “P1” as product to produce - Add the product “P1” as component - save Problem: no validation error is triggered, It's possible to create a MO in which the final product is included in the component > wrong behavior opw-2796750 closes odoo/odoo#87262 X-original-commit: f38727ee4e7b6596a9da5f3285c7622da0ac6772 Signed-off-by: Arnold Moyaux Signed-off-by: Djamel Touati (otd) --- addons/mrp/models/mrp_production.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 971e73d0813..185259a6a9b 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -749,6 +749,13 @@ class MrpProduction(models.Model): if sum(order.move_byproduct_ids.mapped('cost_share')) > 100: raise ValidationError(_("The total cost share for a manufacturing order's by-products cannot exceed 100.")) + @api.constrains('product_id', 'move_raw_ids') + def _check_production_lines(self): + for production in self: + for move in production.move_raw_ids: + if production.product_id == move.product_id: + raise ValidationError(_("The component %s should not be the same as the product to produce.") % production.product_id.display_name) + def write(self, vals): if 'workorder_ids' in self: production_to_replan = self.filtered(lambda p: p.is_planned)