From 3de53fa165baf76cde7f2593d4fb26f2cc7a5383 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 4 Jul 2016 18:30:56 +0200 Subject: [PATCH] [FIX] stock: no rereservation needed in a lot of cases and make sure the moves passed to action_done are those from the recomputation It is possible (in very rare cases) on rereservation that the new reservation will trigger other stock moves than the first reservation. In order to be sure to send the correct stock moves involved to done, it is better to do the rereservation before the splitting of the moves on the total picking. Also rereserve is optimized as it should only reserve for what is given by the pack operations, as the backorder will be reserved later on anyways. --- addons/stock/stock.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 06a59d4eb87..528b4ac35eb 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1661,6 +1661,13 @@ class stock_picking(models.Model): todo_move_ids = [] if not all_op_processed: todo_move_ids += self._create_extra_moves(cr, uid, picking, context=context) + if need_rereserve or not all_op_processed: + moves_reassign = any(x.origin_returned_move_id or x.move_orig_ids for x in picking.move_lines if x.state not in ['done', 'cancel']) + if moves_reassign and (picking.location_id.usage not in ("supplier", "production", "inventory")): + ctx = dict(context) + ctx['reserve_only_ops'] = True #unnecessary to assign other quants than those involved with pack operations as they will be unreserved anyways. + self.rereserve_quants(cr, uid, picking, move_ids=picking.move_lines.ids, context=ctx) + self.do_recompute_remaining_quantities(cr, uid, [picking.id], context=context) #split move lines if needed toassign_move_ids = [] @@ -1681,10 +1688,6 @@ class stock_picking(models.Model): #Assign move as it was assigned before toassign_move_ids.append(new_move) todo_move_ids = list(set(todo_move_ids)) - if need_rereserve or not all_op_processed: - if not picking.location_id.usage in ("supplier", "production", "inventory"): - self.rereserve_quants(cr, uid, picking, move_ids=todo_move_ids, context=context) - self.do_recompute_remaining_quantities(cr, uid, [picking.id], context=context) if todo_move_ids and not context.get('do_only_split'): self.pool.get('stock.move').action_done(cr, uid, todo_move_ids, context=context) elif context.get('do_only_split'): @@ -2464,7 +2467,7 @@ class stock_move(osv.osv): for move in todo_moves: #then if the move isn't totally assigned, try to find quants without any specific domain - if move.state != 'assigned': + if (move.state != 'assigned') and not context.get("reserve_only_ops"): qty_already_assigned = move.reserved_availability qty = move.product_qty - qty_already_assigned quants = quant_obj.quants_get_preferred_domain(cr, uid, qty, move, domain=main_domain[move.id], preferred_domain_list=[], context=context)