From 2e837d69515395d5af71e2dab7f5b71c8af3492a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Mon, 18 Sep 2017 15:16:31 -0700 Subject: [PATCH] [IMP] stock: confirmed moves without an initial demand are assigned To allow users to easily process immediate transfers. --- addons/stock/models/stock_move.py | 14 ++++++++++---- addons/stock/models/stock_picking.py | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 043f4adacf2..52727d083cb 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -534,18 +534,24 @@ class StockMove(models.Model): } moves_todo = self\ .filtered(lambda move: move.state not in ['cancel', 'done'])\ - .sorted(key=lambda move: sort_map.get(move.state, 0)) + .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.move_type == 'one': - if moves_todo[0].state in ('partially_available', 'confirmed'): + 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 'partially_available' else: - # take the less important state among all move_lines. - return moves_todo[-1].state or 'draft' + 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' @api.onchange('product_id', 'product_qty') def onchange_quantity(self): diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index c8ff0586d7c..078b1172ca2 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -312,7 +312,11 @@ class Picking(models.Model): elif all(move.state in ['cancel', 'done'] for move in self.move_lines): self.state = 'done' else: - self.state = self.move_lines._get_relevant_state_among_moves() + relevant_move_state = self.move_lines._get_relevant_state_among_moves() + if relevant_move_state == 'partially_available': + self.state = 'assigned' + else: + self.state = relevant_move_state @api.one @api.depends('move_lines.priority')