From 82bac1c1693d68e3ea978b1eb0b7a80aca35db2a Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 4 Aug 2023 13:04:49 +0200 Subject: [PATCH] [FIX] stock: avoid deleted records Steps to reproduce: - Inventory -> Products -> Product -> Create a tracked serial product P - Click on update quantity and fill in 2 serial numbers - Overview -> Internal Transfers -> New Immediate transfer - Move 2 units of P to another location and save - Reduce the done quantity to 1 Issue: It will raise an error warning us that a record doesn't exist or has been deleted. When decreasing the qty_done of the stock.move.live, since we're in an immediate_transfer, it will also adjust the initial demand. Meaning it will call the move's `write()` which in turn, if the initial demand is changed, can be unreserved. This results in the deletion of the current move.line, which is still accessed after in the loop, raising the error. Part-of: odoo/odoo#129009 --- addons/stock/models/stock_move.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 5fe90d56da9a4..c8a63eadb5e69 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -367,6 +367,9 @@ def _process_decrease(move, quantity): continue ml.qty_done -= qty_ml_dec quantity -= move.product_uom._compute_quantity(qty_ml_dec, move.product_uom, round=False) + if not ml.exists(): + # If decreasing the move line qty_done to 0 let it to be unlinked (i.e. for immediate transfers) + continue # Unreserve if (not move.picking_id.immediate_transfer and move.reserved_availability < move.product_uom_qty): continue