[REF] mrp: clean BoM operations
- make `bom_id` required. No sense to have a operation without BoM - `company_id` of operation is now related - Clean the multiple `allowed_operation_ids` into related fields instead. task-2373638
This commit is contained in:
@@ -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. """
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
<field name="operation_ids"
|
||||
attrs="{'invisible': [('type','not in',('normal','phantom'))]}"
|
||||
groups="mrp.group_mrp_routings"
|
||||
context="{'default_company_id': company_id, 'default_product_tmpl_ids': [product_tmpl_id]}"/>
|
||||
context="{'bom_id_invisible': True, 'default_company_id': company_id, 'default_bom_id': id}"/>
|
||||
</page>
|
||||
<page string="By-products"
|
||||
name="by_products"
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<field name="name"/>
|
||||
<field name="workcenter_id" context="{'default_company_id': company_id}"/>
|
||||
<field name="sequence" groups="base.group_no_one"/>
|
||||
<field name="bom_id" readonly="1"/>
|
||||
<field name="bom_id" invisible="context.get('bom_id_invisible', False)"/>
|
||||
</group><group name="workorder">
|
||||
<field name="workorder_count" invisible="1"/>
|
||||
<field name="time_mode" widget="radio"/>
|
||||
|
||||
Reference in New Issue
Block a user