From aac14d23da591a676dc37160ddee27221c48de1b Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Wed, 17 Apr 2019 08:58:52 +0000 Subject: [PATCH] [FIX] stock: cache invalidation in _action_assign `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 odoo/odoo#32774 Signed-off-by: Simon Lejeune (sle) closes odoo/odoo#32805 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock/models/stock_move.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 735f0c53f94..25cc6163c9c 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -897,8 +897,11 @@ class StockMove(models.Model): """ 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':