From ecdde54c5a9a3ac907f42744ff6eb942ef7d4823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 8 Jan 2021 14:17:30 +0000 Subject: [PATCH] [FIX] stock: `_free_reservation` avoid RecordSet union To improve the scalability of `_free_reservation` avoid use RecordSet union. Simplify the parameter `ml_to_ignore` of the method into `ml_ids_to_ignore` which take only OrderedSet of ids instead of RecordSet. task-2424248 --- addons/stock/models/stock_move_line.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 0abf4a21851..334e6cf4219 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -516,8 +516,7 @@ class StockMoveLine(models.Model): if not ml._should_bypass_reservation(ml.location_id) and float_compare(ml.qty_done, ml.product_uom_qty, precision_rounding=rounding) > 0: qty_done_product_uom = ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id, rounding_method='HALF-UP') extra_qty = qty_done_product_uom - ml.product_qty - ml_to_ignore = self.env['stock.move.line'].browse(ml_ids_to_ignore) - ml._free_reservation(ml.product_id, ml.location_id, extra_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, ml_to_ignore=ml_to_ignore) + ml._free_reservation(ml.product_id, ml.location_id, extra_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, ml_ids_to_ignore=ml_ids_to_ignore) # unreserve what's been reserved if not ml._should_bypass_reservation(ml.location_id) and ml.product_id.type == 'product' and ml.product_qty: try: @@ -594,18 +593,18 @@ class StockMoveLine(models.Model): data['owner_name'] = self.env['res.partner'].browse(vals.get('owner_id')).name record.message_post_with_view(template, values={'move': move, 'vals': dict(vals, **data)}, subtype_id=self.env.ref('mail.mt_note').id) - def _free_reservation(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, ml_to_ignore=None): + def _free_reservation(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, ml_ids_to_ignore=None): """ When editing a done move line or validating one with some forced quantities, it is possible to impact quants that were not reserved. It is therefore necessary to edit or unlink the move lines that reserved a quantity now unavailable. - :param ml_to_ignore: recordset of `stock.move.line` that should NOT be unreserved + :param ml_ids_to_ignore: OrderedSet of `stock.move.line` ids that should NOT be unreserved """ self.ensure_one() - if ml_to_ignore is None: - ml_to_ignore = self.env['stock.move.line'] - ml_to_ignore |= self + if ml_ids_to_ignore is None: + ml_ids_to_ignore = OrderedSet() + ml_ids_to_ignore |= self.ids # Check the available quantity, with the `strict` kw set to `True`. If the available # quantity is greather than the quantity now unavailable, there is nothing to do. @@ -623,8 +622,9 @@ class StockMoveLine(models.Model): ('owner_id', '=', owner_id.id if owner_id else False), ('package_id', '=', package_id.id if package_id else False), ('product_qty', '>', 0.0), - ('id', 'not in', ml_to_ignore.ids), + ('id', 'not in', tuple(ml_ids_to_ignore)), ] + # We take the current picking first, then the pickings with the latest scheduled date current_picking_first = lambda cand: ( cand.picking_id != self.move_id.picking_id,