Skip to content

Commit

Permalink
Merge pull request OCA#815 from jbaudoux/16-stock_available_to_promis…
Browse files Browse the repository at this point in the history
…e_release-mig-refactor

[16.0][FIX] stock_available_to_promise_release: Refactor release_ready compute
  • Loading branch information
sbidoul authored Jan 18, 2024
2 parents 46bdc7d + c6fc246 commit 97ef32b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion stock_available_to_promise_release/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def _run_stock_rule(self):
procurement_requests = []
released_moves = self.env["stock.move"]
# Ensure the release_ready field is correctly computed
self.invalidate_cache(["release_ready"])
self.invalidate_recordset(["release_ready"])
for move in self:
if not move.release_ready:
continue
Expand Down
16 changes: 6 additions & 10 deletions stock_available_to_promise_release/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,17 @@ def _get_shipping_policy(self):

@api.depends(
"move_type",
"move_lines.ordered_available_to_promise_qty",
"move_lines.need_release",
"move_lines.state",
"move_ids.ordered_available_to_promise_qty",
"move_ids.need_release",
"move_ids.state",
)
def _compute_release_ready(self):
for picking in self:
move_lines = picking.move_lines.filtered(
lambda move: move._is_release_needed()
)
moves = picking.move_ids.filtered(lambda move: move._is_release_needed())
release_ready = False
release_ready_count = sum(
1 for move in move_lines if move._is_release_ready()
)
release_ready_count = sum(1 for move in moves if move._is_release_ready())
if picking._get_shipping_policy() == "one":
release_ready = release_ready_count == len(move_lines)
release_ready = release_ready_count == len(moves)
else:
release_ready = bool(release_ready_count)
picking.release_ready_count = release_ready_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def test_unrelease_merged_move(self):
move = self.picking1.move_ids.filtered(lambda m: m.state == "assigned")
line = move.move_line_ids
self.assertEqual(move.product_uom_qty, 2.0)
self.assertEqual(line.product_uom_qty, 2.0)
self.assertEqual(line.reserved_uom_qty, 2.0)

0 comments on commit 97ef32b

Please sign in to comment.