Skip to content

Commit

Permalink
[FIX] stock: avoid deleted records
Browse files Browse the repository at this point in the history
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#129009
  • Loading branch information
clesgow committed Oct 6, 2023
1 parent d2304c8 commit 82bac1c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/stock/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82bac1c

Please sign in to comment.