[FIX] stock: slow downs in stock move line creation

— Create a new product, it's tracking must be set to 'By Unique Serial
    Number';
— Create a new purchase order, with 500 lines. Each line with 10 units
    of quantity of the previously created product;
— Confirm the purchase.

Before this commit, the creation of the stock piking take a quite some
time, and becomes difficult to use this functionality.

Now, the creation of the stock piking time was significantly improved.

opw-2070738

closes odoo/odoo#37107

X-original-commit: a434b087c86888903e320532b5e75856fa32bd13
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
This commit is contained in:
Sebastien LANGE
2019-09-19 07:09:04 +00:00
committed by fw-bot
parent f629cd9672
commit ebda1101e3
+4 -2
View File
@@ -915,6 +915,7 @@ class StockMove(models.Model):
# cache invalidation when actually reserving the move.
reserved_availability = {move: move.reserved_availability for move in self}
roundings = {move: move.product_id.uom_id.rounding for move in self}
move_line_vals_list = []
for move in self.filtered(lambda m: m.state in ['confirmed', 'waiting', 'partially_available']):
rounding = roundings[move]
missing_reserved_uom_quantity = move.product_uom_qty - reserved_availability[move]
@@ -924,7 +925,7 @@ class StockMove(models.Model):
# create the move line(s) but do not impact quants
if move.product_id.tracking == 'serial' and (move.picking_type_id.use_create_lots or move.picking_type_id.use_existing_lots):
for i in range(0, int(missing_reserved_quantity)):
self.env['stock.move.line'].create(move._prepare_move_line_vals(quantity=1))
move_line_vals_list.append(move._prepare_move_line_vals(quantity=1))
else:
to_update = move.move_line_ids.filtered(lambda ml: ml.product_uom_id == move.product_uom and
ml.location_id == move.location_id and
@@ -936,7 +937,7 @@ class StockMove(models.Model):
if to_update:
to_update[0].product_uom_qty += missing_reserved_uom_quantity
else:
self.env['stock.move.line'].create(move._prepare_move_line_vals(quantity=missing_reserved_quantity))
move_line_vals_list.append(move._prepare_move_line_vals(quantity=missing_reserved_quantity))
assigned_moves |= move
else:
if not move.move_orig_ids:
@@ -1027,6 +1028,7 @@ class StockMove(models.Model):
assigned_moves |= move
break
partially_available_moves |= move
self.env['stock.move.line'].create(move_line_vals_list)
partially_available_moves.write({'state': 'partially_available'})
assigned_moves.write({'state': 'assigned'})
self.mapped('picking_id')._check_entire_pack()