From f55a2aa9dfe0303b0a0dcd56161432e09d6cb891 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Mon, 7 Aug 2017 11:18:34 +0200 Subject: [PATCH] [FIX] stock: action_done There was an issue if you make a backorder for a reserved move while not having any quantity done on it. The 0 move will have its `picking_id` field set to the backorder, but not its move lines, and the result was that a stock move could be considered `assigned` while not having any move lines. The test that could show this issue did not fail because of an unwanted call to `_free_reservation` that would call `_recompute_state` on the inconsistent stock move. --- addons/stock/models/stock_move.py | 1 + addons/stock/models/stock_move_line.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index c0deac88257..cb4012ae219 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -911,6 +911,7 @@ class StockMove(models.Model): }) picking.message_post('Backorder Created') #message needs to be improved moves_to_backorder.write({'picking_id': backorder_picking.id}) + moves_to_backorder.mapped('move_line_ids').write({'picking_id': backorder_picking.id}) moves_to_backorder.action_assign() return moves_todo diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index fa373e022f3..faab9a301e5 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -295,7 +295,7 @@ class StockMoveLine(models.Model): rounding = ml.product_uom_id.rounding # if this move line is force assigned, unreserve elsewhere if needed - if float_compare(ml.qty_done, ml.product_qty, precision_rounding=rounding) > 0: + if ml.location_id.should_impact_quants() and float_compare(ml.qty_done, ml.product_qty, precision_rounding=rounding) > 0: extra_qty = ml.qty_done - ml.product_qty ml._free_reservation(ml.product_id, ml.location_id, extra_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id) # unreserve what's been reserved