-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] stock_dynamic_routing: merge moves
- Loading branch information
Showing
4 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
1 change: 1 addition & 0 deletions
1
stock_available_to_promise_release_dynamic_routing/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_move |
36 changes: 36 additions & 0 deletions
36
stock_available_to_promise_release_dynamic_routing/models/stock_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from itertools import groupby | ||
|
||
from odoo import models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
def _after_release_assign_moves(self): | ||
# Trigger the dynamic routing | ||
moves = super()._after_release_assign_moves() | ||
# Check if moves can be merged. We do this after the call to | ||
# _action_assign in super as this could delete some records in self | ||
sorted_moves_by_rule = sorted(moves, key=lambda m: m.picking_id.id) | ||
moves_to_rereserve_ids = [] | ||
new_moves = self.browse() | ||
for _picking_id, move_list in groupby( | ||
sorted_moves_by_rule, key=lambda m: m.picking_id.id | ||
): | ||
moves = self.browse(m.id for m in move_list) | ||
merged_moves = moves._merge_moves() | ||
new_moves |= merged_moves | ||
if moves != merged_moves: | ||
for move in merged_moves: | ||
if not move.quantity_done: | ||
moves_to_rereserve_ids.append(move.id) | ||
if moves_to_rereserve_ids: | ||
moves_to_rereserve = self.browse(moves_to_rereserve_ids) | ||
moves_to_rereserve._do_unreserve() | ||
moves_to_rereserve.with_context( | ||
exclude_apply_dynamic_routing=True | ||
)._action_assign() | ||
return new_moves |