diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 0ac5377b6b2..ab4dba26bc1 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -668,16 +668,17 @@ class StockMoveLine(models.Model): # 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'] + to_unlink_candidates = set() rounding = self.product_uom_id.rounding 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 if candidate.qty_done: + move_to_recompute_state |= candidate.move_id candidate.product_uom_qty = 0.0 else: - candidate.unlink() + to_unlink_candidates.add(candidate.id) if float_is_zero(quantity, precision_rounding=rounding): break else: @@ -689,6 +690,7 @@ class StockMoveLine(models.Model): candidate.product_uom_qty = self.product_id.uom_id._compute_quantity(quantity_split, candidate.product_uom_id, rounding_method='HALF-UP') move_to_recompute_state |= candidate.move_id break + self.env['stock.move.line'].browse(to_unlink_candidates).unlink() move_to_recompute_state._recompute_state() def _should_bypass_reservation(self, location):