diff --git a/mrp_subcontracting_bom_dual_use/models/mrp_bom.py b/mrp_subcontracting_bom_dual_use/models/mrp_bom.py index b4c8efbad..5dba682ca 100644 --- a/mrp_subcontracting_bom_dual_use/models/mrp_bom.py +++ b/mrp_subcontracting_bom_dual_use/models/mrp_bom.py @@ -8,6 +8,18 @@ class MrpBom(models.Model): allow_in_regular_production = fields.Boolean(string="Allow in regular production") + @api.constrains("operation_ids", "type", "allow_in_regular_production") + def _check_subcontracting_no_operation(self): + """Prevent ValidationError if 'Allow in regular production' is checked""" + domain = [ + ("type", "=", "subcontract"), + ("allow_in_regular_production", "=", False), + ("operation_ids", "!=", False), + ] + if self.filtered_domain(domain): + super()._check_subcontracting_no_operation() + return False + @api.model def _bom_find_domain( self, diff --git a/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py b/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py index dca8443a1..777ace650 100644 --- a/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py +++ b/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py @@ -17,6 +17,7 @@ class TestMrpSubcontractingBomDualUse(common.SavepointCase): } ) cls.component_a = cls.env["product.product"].create({"name": "Test Comp A"}) + cls.workcenter = cls.env["mrp.workcenter"].create({"name": "Test workcenter"}) cls.mrp_production_model = cls.env["mrp.production"] def _create_bom(self, bom_type): @@ -30,7 +31,9 @@ class TestMrpSubcontractingBomDualUse(common.SavepointCase): with mrp_bom_form.bom_line_ids.new() as line_form: line_form.product_id = self.component_a line_form.product_qty = 1 - + with mrp_bom_form.operation_ids.new() as operation_form: + operation_form.name = "Test operation" + operation_form.workcenter_id = self.workcenter return mrp_bom_form.save() def test_mrp_production_misc_bom_normal(self): @@ -66,3 +69,4 @@ class TestMrpSubcontractingBomDualUse(common.SavepointCase): self._product_replenish(self.product, 1) item = self.mrp_production_model.search([("product_id", "=", self.product.id)]) self.assertEqual(item.bom_id, bom) + self.assertIn(self.workcenter, item.workorder_ids.mapped("workcenter_id")) diff --git a/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml b/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml index 815f0ca2c..eb336dd2d 100644 --- a/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml +++ b/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml @@ -10,6 +10,16 @@ attrs="{'invisible': [('type','!=','subcontract')]}" /> + + {'invisible': [('type', '=', 'subcontract'),('allow_in_regular_production','=',False)]} + + + {'invisible': [('type', '=', 'subcontract'),('allow_in_regular_production','=',False)]} +