Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions purchase_all_shipments/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ class StockMove(models.Model):
_inherit = "stock.move"

def _get_move_dest_ids(self):
"""Recursively get all destination moves"""
res = self.filtered("move_dest_ids").mapped("move_dest_ids")
if res.filtered("move_dest_ids"):
res |= res.filtered("move_dest_ids")._get_move_dest_ids()
return res
"""Recursively get all destination moves with cycle protection"""
visited = set()

def _get_dest_recursive(moves):
result = self.env["stock.move"]
for move in moves:
if move.id not in visited:
visited.add(move.id)
dest_moves = move.move_dest_ids
result |= dest_moves
if dest_moves:
result |= _get_dest_recursive(dest_moves)
return result

return _get_dest_recursive(self.filtered("move_dest_ids"))