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):