mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_subcontracting_bom_dual_use: Allow operations in subcontracting BoMs.
TT38585
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -10,6 +10,16 @@
|
||||
attrs="{'invisible': [('type','!=','subcontract')]}"
|
||||
/>
|
||||
</field>
|
||||
<page name="operations" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'invisible': [('type', '=', 'subcontract'),('allow_in_regular_production','=',False)]}</attribute>
|
||||
</page>
|
||||
<field name="operation_ids" position="attributes">
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'invisible': [('type', '=', 'subcontract'),('allow_in_regular_production','=',False)]}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user