From 78528596efefd0a08a10d906c1f0d8ae8af223c5 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 24 Nov 2016 17:26:11 +0100 Subject: [PATCH] [FIX] stock: picking's state according to its move lines There are some problems in the way the picking compute its state according to its move lives if the delivery strategy is partial. When a picking was in a partially available state and then you would force availability, the state would stay in partial availability. Therefore, we changed the way the state is calculated more like it was done before. This issue stems from the new API migration. --- addons/stock/models/stock_picking.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 8b4b73d56eb..5a26aebbced 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -314,22 +314,18 @@ class Picking(models.Model): self.state = 'cancel' elif all(move.state in ['cancel', 'done'] for move in self.move_lines): self.state = 'done' - elif self.move_type == 'one': - ordered_moves = self.move_lines.filtered( - lambda move: move.state not in ['cancel', 'done'] - ).sorted( - key=lambda move: (move.state == 'assigned' and 2) or (move.state == 'waiting' and 1) or 0, reverse=False - ) - self.state = ordered_moves[0].state else: - filtered_moves = self.move_lines.filtered(lambda move: move.state not in ['cancel', 'done']) - if not all(move.state == 'assigned' for move in filtered_moves) and any(move.state == 'assigned' for move in filtered_moves): - self.state = 'partially_available' - elif any(move.partially_available for move in filtered_moves): + # We sort our moves by importance of state: "confirmed" should be first, then we'll have + # "waiting" and finally "assigned" at the end. + moves_todo = self.move_lines\ + .filtered(lambda move: move.state not in ['cancel', 'done'])\ + .sorted(key=lambda move: (move.state == 'assigned' and 2) or (move.state == 'waiting' and 1) or 0) + if self.move_type == 'one': + self.state = moves_todo[0].state + elif moves_todo[0].state != 'assigned' and any(x.partially_available or x.state == 'assigned' for x in moves_todo): self.state = 'partially_available' else: - ordered_moves = filtered_moves.sorted(key=lambda move: (move.state == 'assigned' and 2) or (move.state == 'waiting' and 1) or 0, reverse=True) - self.state = ordered_moves[0].state + self.state = moves_todo[-1].state @api.one @api.depends('move_lines.priority')