[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) <arm@odoo.com>
Signed-off-by: DavidFesquet <dafr@odoo.com>
This commit is contained in:
David (dafr)
2022-08-18 19:58:53 +02:00
parent f02e532c76
commit 4c85ca43c1
+1 -1
View File
@@ -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()