Skip to content

Commit

Permalink
[FIX] stock: cache invalidation in _action_assign
Browse files Browse the repository at this point in the history
`reserved_availability` is a computed field of a move depending on its
move lines. We access this field at each iteration of the loop over the
moves to assign and then we create a new move line for it. This triggers
an invalidation of this field, The next iteration will again access this
field and prefetch it for all the next records.

We read the field out of the loop and don't access it again to prevent
these prefetch/invalidation issues.

Confirmation of a PO of ~800 lines goes from 5 minutes to 1 minute.

opw-1953398

closes #32774

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
  • Loading branch information
sle-odoo authored and xdu-odoo committed Apr 18, 2019
1 parent e7ce0b4 commit 7035166
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion addons/stock/models/stock_move.py
Expand Up @@ -897,8 +897,11 @@ def _action_assign(self):
"""
assigned_moves = self.env['stock.move']
partially_available_moves = self.env['stock.move']
# Read the `reserved_availability` field of the moves out of the loop to prevent unwanted
# cache invalidation when actually reserving the move.
reserved_availability = {move: move.reserved_availability for move in self}
for move in self.filtered(lambda m: m.state in ['confirmed', 'waiting', 'partially_available']):
missing_reserved_uom_quantity = move.product_uom_qty - move.reserved_availability
missing_reserved_uom_quantity = move.product_uom_qty - reserved_availability[move]
missing_reserved_quantity = move.product_uom._compute_quantity(missing_reserved_uom_quantity, move.product_id.uom_id, rounding_method='HALF-UP')
if move.location_id.should_bypass_reservation()\
or move.product_id.type == 'consu':
Expand Down

0 comments on commit 7035166

Please sign in to comment.