diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 5e4fb1ff29c..dc40c2b9a68 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1482,6 +1482,7 @@ Please change the quantity done or the rounding precision of your unit of measur taken_quantity = 0 # Find a candidate move line to update or create a new one. + serial_move_line_vals = [] for reserved_quant, quantity in quants: to_update = next((line for line in self.move_line_ids if line._reservation_is_updatable(quantity, reserved_quant)), False) if to_update: @@ -1492,9 +1493,11 @@ Please change the quantity done or the rounding precision of your unit of measur to_update.with_context(bypass_reservation_update=True).reserved_uom_qty += uom_quantity else: if self.product_id.tracking == 'serial': - self.env['stock.move.line'].create([self._prepare_move_line_vals(quantity=1, reserved_quant=reserved_quant) for i in range(int(quantity))]) + # Move lines with serial tracked product_id cannot be to-update candidates. Delay the creation to speed up candidates search + create. + serial_move_line_vals.extend([self._prepare_move_line_vals(quantity=1, reserved_quant=reserved_quant) for i in range(int(quantity))]) else: self.env['stock.move.line'].create(self._prepare_move_line_vals(quantity=quantity, reserved_quant=reserved_quant)) + self.env['stock.move.line'].create(serial_move_line_vals) return taken_quantity def _should_bypass_reservation(self, forced_location=False):