[FIX] stock: avoid crash of _get_relevant_state_among_moves

Avoid crashing if no relevant move is found.

X-original-commit: fee99ff5d3db559081240dfca4b0809dde331ce0
This commit is contained in:
Nicolas Martinelli
2020-04-14 12:00:58 +00:00
parent 71f2f06c61
commit 9640003b5c
+5 -5
View File
@@ -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):