Skip to content

Commit 5ff413b

Browse files
committed
[IMP] repair_preparation: update repair line after preparation move done
update repair line location and lot after preparation is done
1 parent e822aa4 commit 5ff413b

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

repair_preparation/models/stock_move.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,22 @@ def _prepare_procurement_values(self):
1717
if self.repair_line_id:
1818
res["repair_line_id"] = self.repair_line_id.id
1919
return res
20+
21+
def _action_done(self, cancel_backorder=False):
22+
res = super()._action_done(cancel_backorder=cancel_backorder)
23+
for rec in self:
24+
if not rec.repair_line_id or not rec.state == "done":
25+
continue
26+
vals = {}
27+
move_lines = rec.move_line_ids
28+
lot_id = move_lines.lot_id[0].id if move_lines.lot_id else False
29+
vals["lot_id"] = lot_id
30+
location_id = (
31+
move_lines.location_dest_id[0].id
32+
if move_lines.location_dest_id
33+
else rec.location_dest_id.id
34+
)
35+
if location_id:
36+
vals["location_id"] = location_id
37+
rec.repair_line_id.write(vals)
38+
return res

repair_preparation/tests/test_repair_preparation.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ def setUpClass(cls):
1515
{"name": "product to repair", "type": "product"}
1616
)
1717
cls.product_c = cls.env["product.product"].create(
18-
{"name": "product to consume", "type": "product"}
18+
{"name": "product to consume", "type": "product", "tracking": "lot"}
1919
)
2020
cls.product_c_2 = cls.env["product.product"].create(
2121
{"name": "product to consume 2", "type": "product"}
2222
)
23+
cls.lot = cls.env["stock.lot"].create(
24+
{"name": "lot", "product_id": cls.product_c.id}
25+
)
2326
cls.warehouse = cls.env["stock.warehouse"].create(
2427
{"name": "WH", "code": "wh_test"}
2528
)
@@ -75,7 +78,7 @@ def setUpClass(cls):
7578
cls.product, cls.prep_loc, 1.0
7679
)
7780
cls.env["stock.quant"]._update_available_quantity(
78-
cls.product_c, cls.stock_loc, 10.0
81+
cls.product_c, cls.stock_loc, 10.0, lot_id=cls.lot
7982
)
8083
cls.env["stock.quant"]._update_available_quantity(
8184
cls.product_c_2, cls.stock_loc, 10.0
@@ -203,3 +206,13 @@ def test_preparation_disabled(self):
203206
self.assertEqual(self.repair.state, "done")
204207
self.assertFalse(self.line.preparation_move_ids)
205208
self.assertTrue(self.line.move_id)
209+
210+
def test_update_repair_line_after_preparation(self):
211+
self.test_validate_runs_procurement()
212+
self.line.location_id = self.stock_loc
213+
self.assertFalse(self.line.lot_id)
214+
move_line = self.repair.preparation_picking_ids.move_line_ids
215+
self.assertEqual(move_line.lot_id, self.lot)
216+
self._do_picking(self.repair.preparation_picking_ids)
217+
self.assertEqual(self.line.location_id, self.prep_loc)
218+
self.assertEqual(self.line.lot_id, self.lot)

0 commit comments

Comments
 (0)