From 9640003b5c6e051ca459fbb9fcaf6fab925e28a8 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 8 Apr 2020 14:05:49 +0000 Subject: [PATCH] [FIX] stock: avoid crash of _get_relevant_state_among_moves Avoid crashing if no relevant move is found. X-original-commit: fee99ff5d3db559081240dfca4b0809dde331ce0 --- addons/stock/models/stock_move.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 2449d4ce0fd..4dafe149b2b 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -775,22 +775,22 @@ class StockMove(models.Model): .filtered(lambda move: move.state not in ['cancel', 'done'])\ .sorted(key=lambda move: (sort_map.get(move.state, 0), move.product_uom_qty)) # The picking should be the same for all moves. - if moves_todo[0].picking_id and moves_todo[0].picking_id.move_type == 'one': + if moves_todo[:1].picking_id and moves_todo[:1].picking_id.move_type == 'one': most_important_move = moves_todo[0] if most_important_move.state == 'confirmed': return 'confirmed' if most_important_move.product_uom_qty else 'assigned' elif most_important_move.state == 'partially_available': return 'confirmed' else: - return moves_todo[0].state or 'draft' - elif moves_todo[0].state != 'assigned' and any(move.state in ['assigned', 'partially_available'] for move in moves_todo): + return moves_todo[:1].state or 'draft' + elif moves_todo[:1].state != 'assigned' and any(move.state in ['assigned', 'partially_available'] for move in moves_todo): return 'partially_available' else: - least_important_move = moves_todo[-1] + least_important_move = moves_todo[-1:] if least_important_move.state == 'confirmed' and least_important_move.product_uom_qty == 0: return 'assigned' else: - return moves_todo[-1].state or 'draft' + return moves_todo[-1:].state or 'draft' @api.onchange('product_id') def onchange_product_id(self):