diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index bf48820fcc6..00b6d961943 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -291,7 +291,7 @@ class MrpBomLine(models.Model):
'product.template.attribute.value', string="Apply on Variants", ondelete='restrict',
domain="[('id', 'in', possible_bom_product_template_attribute_value_ids)]",
help="BOM Product Variants needed to apply this line.")
- allowed_operation_ids = fields.Many2many('mrp.routing.workcenter', compute='_compute_allowed_operation_ids')
+ allowed_operation_ids = fields.One2many('mrp.routing.workcenter', related='bom_id.operation_ids')
operation_id = fields.Many2one(
'mrp.routing.workcenter', 'Consumed in Operation', check_company=True,
domain="[('id', 'in', allowed_operation_ids)]",
@@ -343,20 +343,6 @@ class MrpBomLine(models.Model):
for line in self:
line.child_line_ids = line.child_bom_id.bom_line_ids.ids or False
- @api.depends('bom_id')
- def _compute_allowed_operation_ids(self):
- for bom_line in self:
- if not bom_line.bom_id.operation_ids:
- bom_line.allowed_operation_ids = self.env['mrp.routing.workcenter']
- else:
- operation_domain = [
- ('id', 'in', bom_line.bom_id.operation_ids.ids),
- '|',
- ('company_id', '=', bom_line.company_id.id),
- ('company_id', '=', False)
- ]
- bom_line.allowed_operation_ids = self.env['mrp.routing.workcenter'].search(operation_domain)
-
@api.onchange('product_uom_id')
def onchange_product_uom_id(self):
res = {}
@@ -433,25 +419,11 @@ class MrpByProduct(models.Model):
default=1.0, digits='Product Unit of Measure', required=True)
product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True)
bom_id = fields.Many2one('mrp.bom', 'BoM', ondelete='cascade', index=True)
- allowed_operation_ids = fields.Many2many('mrp.routing.workcenter', compute='_compute_allowed_operation_ids')
+ allowed_operation_ids = fields.One2many('mrp.routing.workcenter', related='bom_id.operation_ids')
operation_id = fields.Many2one(
'mrp.routing.workcenter', 'Produced in Operation', check_company=True,
domain="[('id', 'in', allowed_operation_ids)]")
- @api.depends('bom_id')
- def _compute_allowed_operation_ids(self):
- for byproduct in self:
- if not byproduct.bom_id.operation_ids:
- byproduct.allowed_operation_ids = self.env['mrp.routing.workcenter']
- else:
- operation_domain = [
- ('id', 'in', byproduct.bom_id.operation_ids.ids),
- '|',
- ('company_id', '=', byproduct.company_id.id),
- ('company_id', '=', False)
- ]
- byproduct.allowed_operation_ids = self.env['mrp.routing.workcenter'].search(operation_domain)
-
@api.onchange('product_id')
def onchange_product_id(self):
""" Changes UoM if product_id changes. """
diff --git a/addons/mrp/models/mrp_routing.py b/addons/mrp/models/mrp_routing.py
index 32b16664c13..58192f87f82 100644
--- a/addons/mrp/models/mrp_routing.py
+++ b/addons/mrp/models/mrp_routing.py
@@ -16,11 +16,10 @@ class MrpRoutingWorkcenter(models.Model):
'Sequence', default=100,
help="Gives the sequence order when displaying a list of routing Work Centers.")
bom_id = fields.Many2one(
- 'mrp.bom', 'Bill of Material', check_company=True,
- index=True, ondelete='cascade',
+ 'mrp.bom', 'Bill of Material',
+ index=True, ondelete='cascade', required=True,
help="The Bill of Material this operation is linked to")
- company_id = fields.Many2one(
- 'res.company', 'Company', default=lambda self: self.env.company)
+ company_id = fields.Many2one('res.company', 'Company', related='bom_id.company_id')
worksheet_type = fields.Selection([
('pdf', 'PDF'), ('google_slide', 'Google Slide'), ('text', 'Text')],
string="Work Sheet", default="text",
diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py
index 75150cae3a0..4b1557edcb5 100644
--- a/addons/mrp/models/stock_move.py
+++ b/addons/mrp/models/stock_move.py
@@ -90,7 +90,8 @@ class StockMove(models.Model):
'mrp.unbuild', 'Disassembly Order', check_company=True)
consume_unbuild_id = fields.Many2one(
'mrp.unbuild', 'Consumed Disassembly Order', check_company=True)
- allowed_operation_ids = fields.Many2many('mrp.routing.workcenter', compute='_compute_allowed_operation_ids')
+ allowed_operation_ids = fields.One2many(
+ 'mrp.routing.workcenter', related='raw_material_production_id.bom_id.operation_ids')
operation_id = fields.Many2one(
'mrp.routing.workcenter', 'Operation To Consume', check_company=True,
domain="[('id', 'in', allowed_operation_ids)]")
@@ -127,24 +128,6 @@ class StockMove(models.Model):
for move in self:
move.order_finished_lot_ids = move.raw_material_production_id.lot_producing_id
- @api.depends('raw_material_production_id.bom_id')
- def _compute_allowed_operation_ids(self):
- for move in self:
- if (
- not move.raw_material_production_id or
- not move.raw_material_production_id.bom_id or not
- move.raw_material_production_id.bom_id.operation_ids
- ):
- move.allowed_operation_ids = self.env['mrp.routing.workcenter']
- else:
- operation_domain = [
- ('id', 'in', move.raw_material_production_id.bom_id.operation_ids.ids),
- '|',
- ('company_id', '=', self.company_id.id),
- ('company_id', '=', False)
- ]
- move.allowed_operation_ids = self.env['mrp.routing.workcenter'].search(operation_domain)
-
@api.depends('raw_material_production_id.is_locked', 'production_id.is_locked')
def _compute_is_locked(self):
super(StockMove, self)._compute_is_locked()
diff --git a/addons/mrp/tests/test_bom.py b/addons/mrp/tests/test_bom.py
index 9ec7c2bee42..fc241c0592b 100644
--- a/addons/mrp/tests/test_bom.py
+++ b/addons/mrp/tests/test_bom.py
@@ -312,14 +312,17 @@ class TestBoM(TestMrpCommon):
operation.workcenter_id = workcenter
operation.name = 'Prepare biscuits'
operation.time_cycle_manual = 5
+ operation.bom_id = bom_crumble # Can't handle by the testing env
with bom.operation_ids.new() as operation:
operation.workcenter_id = workcenter
operation.name = 'Prepare butter'
operation.time_cycle_manual = 3
+ operation.bom_id = bom_crumble
with bom.operation_ids.new() as operation:
operation.workcenter_id = workcenter
operation.name = 'Mix manually'
operation.time_cycle_manual = 5
+ operation.bom_id = bom_crumble
# TEST BOM STRUCTURE VALUE WITH BOM QUANTITY
report_values = self.env['report.mrp.report_bom_structure']._get_report_data(bom_id=bom_crumble.id, searchQty=11, searchVariant=False)
@@ -409,10 +412,12 @@ class TestBoM(TestMrpCommon):
operation.workcenter_id = workcenter
operation.name = 'Mix cheese and crumble'
operation.time_cycle_manual = 10
+ operation.bom_id = bom_cheese_cake
with bom.operation_ids.new() as operation:
operation.workcenter_id = workcenter_2
operation.name = 'Cake mounting'
operation.time_cycle_manual = 5
+ operation.bom_id = bom_cheese_cake
# TEST CHEESE BOM STRUCTURE VALUE WITH BOM QUANTITY
diff --git a/addons/mrp/views/mrp_bom_views.xml b/addons/mrp/views/mrp_bom_views.xml
index 94afb0e8850..6e7b5384f5a 100644
--- a/addons/mrp/views/mrp_bom_views.xml
+++ b/addons/mrp/views/mrp_bom_views.xml
@@ -103,7 +103,7 @@
+ context="{'bom_id_invisible': True, 'default_company_id': company_id, 'default_bom_id': id}"/>
-
+