[FIX] stock: improve move_line._free_reservation performances

Move candidate.unlink out of the for loop to unlink
records in batch.

Remove to_unlink_candidates.move_id from move_to_recompute as
move_line.unlink() will trigger recompute of their move's state.

---

opw-2585598

closes odoo/odoo#73160

X-original-commit: e2e51c15d082ec17743b73ad1422e4a223268be9
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
Aurélien (avd)
2021-07-02 13:41:07 +00:00
parent f8ffa757c8
commit 8ccacf58af
+4 -2
View File
@@ -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):