From 4c85ca43c1480212a4b271d2d40ac1fb5db54dc3 Mon Sep 17 00:00:00 2001 From: "David (dafr)" Date: Tue, 9 Aug 2022 14:09:42 +0000 Subject: [PATCH] [FIX] stock: Check move_id exist before using it. Reproduce steps: - Create P1: storable, tracked by SN, manufacture - Create C1: storable, tracked by lot - Add 100 unit of C1 in Stock location - Add 2 unit of P1 in Production location - Create BoM for P1 with C1 as component - Create MO for 2 unit of P1 > Confirm > Mass Produce > Generate Serials > Apply => Traceback on ensure_one() In mrp_production.py in _split_productions(), the 'move_id' field is removed before unlink() is called in order to avoid calling recompute_state(). As move_id is not guaranteed to exist, we need to check before using it. OPW-2878461 closes odoo/odoo#98391 X-original-commit: 6f2b7af37468d97b8dd4eb6c8e4bdcbaf472a331 Signed-off-by: Arnold Moyaux (arm) Signed-off-by: DavidFesquet --- addons/stock/models/stock_move_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 4b58ef07e6d..66523810a11 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -485,7 +485,7 @@ class StockMoveLine(models.Model): precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') for ml in self: # Unlinking a move line should unreserve. - if not float_is_zero(ml.reserved_qty, precision_digits=precision) and not ml.move_id._should_bypass_reservation(ml.location_id): + if not float_is_zero(ml.reserved_qty, precision_digits=precision) and ml.move_id and not ml.move_id._should_bypass_reservation(ml.location_id): self.env['stock.quant']._update_reserved_quantity(ml.product_id, ml.location_id, -ml.reserved_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, strict=True) moves = self.mapped('move_id') res = super(StockMoveLine, self).unlink()