Skip to content

Commit

Permalink
Merge PR OCA#755 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by jbaudoux
  • Loading branch information
OCA-git-bot committed Oct 4, 2023
2 parents 97fe352 + c5da43e commit 4f5ebb6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stock_move_source_relocate/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def _action_assign(self):
unconfirmed_moves._apply_source_relocate()

def _apply_source_relocate(self):
"""Apply relocation rules.
Returns the recordset of confirmed and partially available moves
"""
# Read the `reserved_availability` field of the moves out of the loop
# to prevent unwanted cache invalidation when actually reserving.
reserved_availability = {move: move.reserved_availability for move in self}
Expand All @@ -35,20 +39,26 @@ def _apply_source_relocate(self):
"Try to relocate moves of operation type (%s)"
% ", ".join(self.picking_type_id.mapped("name"))
)
res_ids = []
for move in self:
# We don't need to ignore moves with "_should_bypass_reservation()
# is True" because they are reserved at this point.
relocation = self.env["stock.source.relocate"]._rule_for_move(move)
if not relocation or relocation.relocate_location_id == move.location_id:
res_ids.append(move.id)
continue
relocated = move._apply_source_relocate_rule(
relocation, reserved_availability, roundings
)
if relocated:
relocated_ids.append(relocated.id)
res_ids.append(relocated.id)
else:
res_ids.append(move.id)
if relocated_ids:
_logger.debug("Relocated moves %s" % relocated_ids)
self.browse(relocated_ids)._after_apply_source_relocate_rule()
return self.browse(res_ids)

def _apply_source_relocate_rule(self, relocation, reserved_availability, roundings):
self.ensure_one()
Expand Down

0 comments on commit 4f5ebb6

Please sign in to comment.