Skip to content

Commit

Permalink
[FIX] stock_dynamic_routing: merge moves
Browse files Browse the repository at this point in the history
Merge reclassified moves after release
  • Loading branch information
jbaudoux committed Sep 1, 2023
1 parent 40da141 commit f6c141c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
7 changes: 4 additions & 3 deletions stock_available_to_promise_release/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ def _run_stock_rule(self):
)
self.env["procurement.group"].run_defer(procurement_requests)

released_moves._after_release_assign_moves()
released_moves._after_release_update_chain()
assigned_moves = released_moves._after_release_assign_moves()
assigned_moves._after_release_update_chain()

return released_moves
return assigned_moves

def _before_release(self):
"""Hook that aims to be overridden."""
Expand All @@ -491,6 +491,7 @@ def _after_release_assign_moves(self):
).ids
moves = self.browse(move_ids)
moves._action_assign()
return moves

def _release_split(self, remaining_qty):
"""Split move and put remaining_qty to a backorder move."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{
"name": "Available to Promise Release - Dynamic Routing",
"summary": "Glue between moves release and dynamic routing",
"author": "Camptocamp, Odoo Community Association (OCA)",
"author": "Camptocamp,BCIM,Odoo Community Association (OCA)",
"maintainers": ["jbaudoux"],
"website": "https://github.com/OCA/wms",
"category": "Warehouse Management",
"version": "14.0.1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Jacques-Etienne Baudoux (BCIM) <[email protected]>
* Guewen Baconnier <[email protected]>
* `Trobz <https://trobz.com>`_:
* Dung Tran <[email protected]>
Expand Down

0 comments on commit f6c141c

Please sign in to comment.