[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) <sle@openerp.com>

closes odoo/odoo#32805

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Simon Lejeune
2019-04-18 12:55:33 +00:00
committed by Xavier Dubuc
parent e07ecf298f
commit aac14d23da
+4 -1
View File
@@ -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':