Skip to content

Commit

Permalink
[IMP] stock_warehouse_flow: assign_picking only if needed
Browse files Browse the repository at this point in the history
Do not call assign_picking on apply
if it is getting called from action_confirm
  • Loading branch information
mt-software-de authored and sebalix committed Oct 31, 2023
1 parent ead534f commit 9f470ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion stock_warehouse_flow/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def _action_confirm(self, merge=True, merge_into=False):
if not move._apply_flow_on_action_confirm():
move_ids_to_confirm.append(move.id)
continue
move_ids_to_confirm += FLOW._search_and_apply_for_move(move).ids
# Do not assign a picking within the _apply_on_move method
# because it gets called later from _action_confirm itself
move_ids_to_confirm += FLOW._search_and_apply_for_move(
move, assign_picking=False
).ids
moves_to_confirm = self.browse(move_ids_to_confirm)
return super(StockMove, moves_to_confirm)._action_confirm(
merge=merge, merge_into=merge_into
Expand Down
13 changes: 7 additions & 6 deletions stock_warehouse_flow/models/stock_warehouse_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ def _search_for_move(self, move):
return self.search(domain)

@api.model
def _search_and_apply_for_move(self, move):
def _search_and_apply_for_move(self, move, assign_picking=True):
move.ensure_one()
flows = self._search_for_move(move)
if not flows:
return move
return flows.apply_on_move(move)
return flows.apply_on_move(move, assign_picking)

def apply_on_move(self, move):
def apply_on_move(self, move, assign_picking=True):
move_ids = []
flows = self
for flow in self:
Expand All @@ -444,7 +444,7 @@ def apply_on_move(self, move):
# Try to apply the rest of the flows to the split move
for split_move in split_moves:
move_ids += (flows - flow).apply_on_move(split_move).ids
flow._apply_on_move(move)
flow._apply_on_move(move, assign_picking)
return move.browse(move_ids)
raise UserError(
_(
Expand Down Expand Up @@ -521,7 +521,7 @@ def split_move(self, move):
return self._split_move_simple(move)
return split_moves

def _apply_on_move(self, move):
def _apply_on_move(self, move, assign_picking=True):
"""Apply the flow configuration on the move."""
if not self:
return False
Expand All @@ -535,7 +535,8 @@ def _apply_on_move(self, move):
)
move.procure_method = rule.procure_method
move.rule_id = rule
move._assign_picking()
if assign_picking:
move._assign_picking()

def write(self, vals):
res = super().write(vals)
Expand Down

0 comments on commit 9f470ab

Please sign in to comment.