Skip to content

Commit

Permalink
try to chain a dest mode without lot_id
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliesoutiras committed Jun 13, 2024
1 parent 044018e commit ccc5c05
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
20 changes: 19 additions & 1 deletion stock_restrict_lot/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,25 @@ def get_all_orig_moves(self):

def write(self, vals):
if "restrict_lot_id" not in vals:
return super().write(vals)
res = super().write(vals)
if "move_dest_ids" in vals or "move_orig_ids" in vals:
for move in self:
chained_moves = (
move | move.get_all_dest_moves() | move.get_all_orig_moves()
)
if not move.restrict_lot_id and move.state not in ["done", "cancel"]:
# update restrict_lot_id on current move from chained_moves
if chained_moves.restrict_lot_id:
move.restrict_lot_id = chained_moves.restrict_lot_id[0]
else:
# update chained_moves
to_update_move = chained_moves.filtered(
lambda sm: sm.state not in ['done', 'cancel'] and
sm.restrict_lot_id != move.restrict_lot_id
)
to_update_move.restrict_lot_id = move.restrict_lot_id
else:
return res
else:
restrict_lot_id = vals.pop("restrict_lot_id")
restrict_lot = self.env["stock.lot"].browse(restrict_lot_id)
Expand Down
24 changes: 22 additions & 2 deletions stock_restrict_lot/tests/test_restrict_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _create_move_with_lot(self):
)
return move, new_lot

def _create_move_dest(self):
def _create_move_dest(self, with_lot = True):
return self.env["stock.move"].create(
{
"product_id": self.product.id,
Expand All @@ -60,7 +60,7 @@ def _create_move_dest(self):
"warehouse_id": self.warehouse.id,
"route_ids": [(6, 0, self.warehouse.delivery_route_id.ids)],
"state": "waiting",
"restrict_lot_id": self.lot.id,
"restrict_lot_id": self.lot.id if with_lot else False,
}
)

Expand Down Expand Up @@ -278,13 +278,33 @@ def test_restrict_lot_propagation_dest_moves(self):
move.restrict_lot_id = new_lot.id
self.assertEqual(move_dest.restrict_lot_id, new_lot)

def test_restrict_lot_propagation_dest_moves_without_lot(self):
move, new_lot = self._create_move_with_lot()
move_dest = self._create_move_dest(False)
move.move_dest_ids = [(4, move_dest.id)]
chained_moves = (
move | move.get_all_dest_moves() | move.get_all_orig_moves()
)
self.assertEqual(chained_moves.restrict_lot_id, self.lot)
self.assertEqual(move_dest.restrict_lot_id, self.lot)
move.restrict_lot_id = new_lot.id
self.assertEqual(move_dest.restrict_lot_id, new_lot)

def test_restrict_lot_propagation_origin_moves(self):
move, new_lot = self._create_move_with_lot()
orig_move = move.move_orig_ids
self.assertEqual(orig_move.restrict_lot_id, self.lot)
move.restrict_lot_id = new_lot.id
self.assertEqual(orig_move.restrict_lot_id, new_lot)

def test_restrict_lot_propagation_orig_moves_without_lot(self):
move, new_lot = self._create_move_with_lot()
move_dest = self._create_move_dest(False)
move_dest.move_orig_ids = [(4, move.id)]
self.assertEqual(move_dest.restrict_lot_id, self.lot)
move.restrict_lot_id = new_lot.id
self.assertEqual(move_dest.restrict_lot_id, new_lot)

def test_restrict_lot_propagation_origin_and_dest_moves(self):
move, new_lot = self._create_move_with_lot()
move_dest = self._create_move_dest()
Expand Down

0 comments on commit ccc5c05

Please sign in to comment.