Skip to content

Commit ee11a6d

Browse files
committed
Merge PR #894 into 16.0
Signed-off-by jbaudoux
2 parents 0b9040f + 28842bf commit ee11a6d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stock_available_to_promise_release/models/stock_move.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,23 @@ def _is_release_needed(self):
313313
def _is_release_ready(self):
314314
"""Checks if a move itself is ready for release
315315
without considering the picking release_ready
316+
317+
318+
Be careful, when calling this method, you must ensure that the
319+
'ordered_available_to_promise_qty' field is up to date. If not,
320+
you should invalidate the cache before calling this method. This
321+
is not done automatically to avoid unnecessary cache invalidation
322+
and to allow batch computation. The `_is_release_ready` method
323+
is designed to be called on a single record. If we do the cache
324+
invalidation here, it would be done for each record, which means
325+
that the computation of the 'ordered_available_to_promise_qty'
326+
would be done for each record, which is not efficient.
316327
"""
317328
self.ensure_one()
318329
if not self._is_release_needed() or self.state == "draft":
319330
return False
320331
release_policy = self.picking_id.release_policy
321332
rounding = self.product_id.uom_id.rounding
322-
# computed field has no depends set, invalidate cache before reading
323-
self.invalidate_recordset(["ordered_available_to_promise_qty"])
324333
ordered_available_to_promise_qty = self.ordered_available_to_promise_qty
325334
if release_policy == "one":
326335
return (
@@ -349,6 +358,7 @@ def _get_release_ready_depends(self):
349358

350359
@api.depends(lambda self: self._get_release_ready_depends())
351360
def _compute_release_ready(self):
361+
self.invalidate_recordset(["ordered_available_to_promise_qty"])
352362
for move in self:
353363
release_ready = move._is_release_ready()
354364
if release_ready and move.picking_id.release_policy == "one":

stock_available_to_promise_release/models/stock_picking.py

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def _get_release_ready_depends(self):
8282
# invalidate cache before accessing this release_ready computed value
8383
@api.depends(lambda self: self._get_release_ready_depends())
8484
def _compute_release_ready(self):
85+
self.move_ids.invalidate_recordset(["ordered_available_to_promise_qty"])
8586
for picking in self:
8687
moves = picking.move_ids.filtered(lambda move: move._is_release_needed())
8788
release_ready = False

0 commit comments

Comments
 (0)