Skip to content

Commit dba88b3

Browse files
[FIX] repair_stock_consumption_step: preserve lot_id on preparation picking
1 parent dd69e14 commit dba88b3

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

repair_stock_consumption_step/models/repair_order.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,26 @@ def action_repair_done(self):
4848
"location_dest_id": moves[0].location_dest_id.id,
4949
}
5050
)
51+
52+
# Preserve lot info before unlink the move lines
53+
move_id_lots_ids_map = {}
54+
for move in moves:
55+
move_id_lots_ids_map[move.id] = move.move_line_ids.mapped("lot_id").ids
56+
5157
moves.picking_id = picking.id
5258
moves.move_line_ids.unlink()
53-
moves._do_unreserve()
5459
moves._action_confirm()
5560
moves._action_assign()
56-
moves.move_line_ids.picking_id = picking.id
61+
62+
# Reset lot_id on the new move lines
63+
for move in moves:
64+
lot_ids = move_id_lots_ids_map.get(move.id)
65+
if not lot_ids:
66+
continue
67+
for line in move.move_line_ids:
68+
if not line.lot_id:
69+
line.lot_id = lot_ids.pop(0)
70+
5771
rec.consumption_picking_id = picking
5872
rec.state = "consumption"
5973
return res

repair_stock_consumption_step/tests/test_repair_stock_consumption_step.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def setUpClass(cls):
4848
"product_id": cls.product_c.id,
4949
"product_uom_qty": 2.0,
5050
"location_id": cls.repair_loc.id,
51+
"lot_id": cls.env["stock.lot"]
52+
.create({"name": "Test Lot", "product_id": cls.product_c.id})
53+
.id,
5154
}
5255
)
5356
cls.env["stock.quant"]._update_available_quantity(
@@ -81,6 +84,7 @@ def test_repair_done_with_consumption_step(self):
8184
self.assertTrue(self.repair.consumption_picking_id)
8285
moves = self.env["stock.move"].search([("repair_id", "=", self.repair.id)])
8386
pick = self.repair.consumption_picking_id
87+
self.assertEqual(self.repair.operations.lot_id, pick.move_line_ids.lot_id)
8488
self.assertTrue(moves)
8589
self.assertEqual(pick.move_ids, moves)
8690
self.assertSetEqual(set(moves.mapped("state")), {"assigned"})

0 commit comments

Comments
 (0)