[IMP] mrp: choose operation to consume new product
This commit adds the possibility to choose in which operation a new product will be consumed. New product can be added to the production once the manufacturing order is in state draft. Before this commit, the new product was consumed automatically in the last workorder. Task: 2121714
This commit is contained in:
@@ -699,12 +699,14 @@ class MrpProduction(models.Model):
|
||||
# one opeation in the routing then it will need all BoM lines.
|
||||
bom_line_ids = self.env['mrp.bom.line']
|
||||
if len(self.routing_id.operation_ids) == 1:
|
||||
bom_line_ids = self.bom_id.bom_line_ids
|
||||
moves_in_first_operation = self.move_raw_ids
|
||||
else:
|
||||
bom_line_ids = self.bom_id.bom_line_ids.filtered(lambda bl: bl.operation_id == first_operation)
|
||||
bom_line_ids = bom_line_ids.filtered(lambda bl: not bl._skip_bom_line(self.product_id))
|
||||
moves_in_first_operation = self.move_raw_ids.filtered(lambda move: move.operation_id == first_operation)
|
||||
moves_in_first_operation = moves_in_first_operation.filtered(
|
||||
lambda move: move.bom_line_id and
|
||||
not move.bom_line_id._skip_bom_line(self.product_id)
|
||||
)
|
||||
|
||||
moves_in_first_operation = self.move_raw_ids.filtered(lambda m: m.bom_line_id in bom_line_ids)
|
||||
if all(move.state == 'assigned' for move in moves_in_first_operation):
|
||||
return 'assigned'
|
||||
return 'confirmed'
|
||||
@@ -918,7 +920,13 @@ class MrpProduction(models.Model):
|
||||
workorders[-1]._start_nextworkorder()
|
||||
workorders += workorder
|
||||
|
||||
moves_raw = self.move_raw_ids.filtered(lambda move: move.operation_id == operation and move.bom_line_id.bom_id.routing_id == bom.routing_id)
|
||||
# get the raw moves to attach to this operation
|
||||
moves_raw = self.env['stock.move']
|
||||
for move in self.move_raw_ids:
|
||||
if move.operation_id == operation and move.bom_line_id.bom_id.routing_id == bom.routing_id:
|
||||
moves_raw |= move
|
||||
if move.operation_id == operation and not move.bom_line_id:
|
||||
moves_raw |= move
|
||||
moves_finished = self.move_finished_ids.filtered(lambda move: move.operation_id == operation)
|
||||
|
||||
# - Raw moves from a BoM where a routing was set but no operation was precised should
|
||||
|
||||
@@ -79,7 +79,9 @@ class StockMove(models.Model):
|
||||
consume_unbuild_id = fields.Many2one(
|
||||
'mrp.unbuild', 'Consumed Disassembly Order', check_company=True)
|
||||
operation_id = fields.Many2one(
|
||||
'mrp.routing.workcenter', 'Operation To Consume', check_company=True) # TDE FIXME: naming
|
||||
'mrp.routing.workcenter', 'Operation To Consume', check_company=True,
|
||||
domain="[('routing_id', '=', routing_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]")
|
||||
routing_id = fields.Many2one(related='raw_material_production_id.routing_id')
|
||||
workorder_id = fields.Many2one(
|
||||
'mrp.workorder', 'Work Order To Consume', check_company=True)
|
||||
# Quantities to process, in normalized UoMs
|
||||
|
||||
@@ -1758,3 +1758,36 @@ class TestRoutingAndKits(SavepointCase):
|
||||
wo2.button_start()
|
||||
self.assertEqual(wo2.qty_producing, 10)
|
||||
self.assertEqual(wo2.finished_lot_id, lot1)
|
||||
|
||||
def test_add_move(self):
|
||||
""" Make a production using multi step routing. Add an additional move
|
||||
on a specific operation and check that the produce is consumed into the
|
||||
right workorder. """
|
||||
self.bom_finished1.consumption = 'flexible'
|
||||
add_product = self.env['product.product'].create({
|
||||
'name': 'Additional',
|
||||
})
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.product_id = self.finished1
|
||||
mo_form.bom_id = self.bom_finished1
|
||||
mo_form.product_qty = 10.0
|
||||
mo = mo_form.save()
|
||||
|
||||
mo_form = Form(mo)
|
||||
with mo_form.move_raw_ids.new() as move:
|
||||
move.name = mo.name
|
||||
move.product_id = add_product
|
||||
move.product_uom = add_product.uom_id
|
||||
move.location_id = mo.location_src_id
|
||||
move.location_dest_id = mo.production_location_id
|
||||
move.product_uom_qty = 2
|
||||
move.operation_id = mo.routing_id.operation_ids[0]
|
||||
mo = mo_form.save()
|
||||
self.assertEqual(len(mo.move_raw_ids), 3)
|
||||
mo.action_confirm()
|
||||
self.assertEqual(mo.move_raw_ids.mapped('state'), ['confirmed'] * 3)
|
||||
mo.button_plan()
|
||||
self.assertEqual(len(mo.workorder_ids), 3)
|
||||
wo1 = mo.workorder_ids[0]
|
||||
lines = wo1.raw_workorder_line_ids
|
||||
self.assertEqual(lines.product_id, add_product)
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
<span> / </span>
|
||||
<span><field name="reserved_availability" nolabel="1"/></span>
|
||||
</div>
|
||||
<field name="operation_id" attrs="{'invisible': ['|', ('parent.routing_id', '=', False), ('id', '!=', False)]}" groups="mrp.group_mrp_routings"/>
|
||||
<field name="routing_id" invisible="1"/>
|
||||
<field name="unit_factor" invisible="1"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="is_done" invisible="1"/>
|
||||
<field name="workorder_id" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user