diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index ae675f7c71c..d490a3e7053 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -487,7 +487,7 @@ class StockMoveLine(models.Model): if quantity > available_quantity: # We now have to find the move lines that reserved our now unavailable quantity. We # take care to exclude ourselves and the move lines were work had already been done. - oudated_move_lines_domain = [ + outdated_move_lines_domain = [ ('move_id.state', 'not in', ['done', 'cancel']), ('product_id', '=', product_id.id), ('lot_id', '=', lot_id.id if lot_id else False), @@ -497,14 +497,15 @@ class StockMoveLine(models.Model): ('product_qty', '>', 0.0), ('id', 'not in', ml_to_ignore.ids), ] - oudated_candidates = self.env['stock.move.line'].search(oudated_move_lines_domain) + current_picking_first = lambda cand: cand.picking_id != self.move_id.picking_id + outdated_candidates = self.env['stock.move.line'].search(outdated_move_lines_domain).sorted(current_picking_first) # As the move's state is not computed over the move lines, we'll have to manually # recompute the moves which we adapted their lines. move_to_recompute_state = self.env['stock.move'] rounding = self.product_uom_id.rounding - for candidate in oudated_candidates: + for candidate in outdated_candidates: if float_compare(candidate.product_qty, quantity, precision_rounding=rounding) <= 0: quantity -= candidate.product_qty move_to_recompute_state |= candidate.move_id