From 86cb78740b66d868131ffc808092cec19f077bee Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 14 Feb 2019 10:06:44 +0000 Subject: [PATCH] [FIX] stock: picking to scratch location with BO Usecase to reproduce: - Create an internal picking from stock to scrap - Add some scrap move inside due to scrap button in header - Add some move with initial demand for future - Mark the picking as done and validate it - The wizard asking for a backorder appear -> Validate or No backorder The moves with initial demand are duplicated(one new move for each without intial demand nor quantity done) A note is logged in the chatter with backorder False has been created. There is a problem since _action_done on a scrap move from scrap model will process the scrap move individualy but will create a back order (commit e088acbc0fdc3ef6d320bdaaf2d08244c883e8c4 try to fix this issue) However when we create a picking that goes to scrap location, the back order will not be created since all moves are scrapped. With the current configuration we can't guess in _action_done if it comes from scrap or picking validate that goes to a scrap location. The current solution is to use a context key in order to indicate if the call come from picking validate or scrap. If it comes from scrap do not create a back order no matter the case. If it comes from picking, follow the standard beahvior with a backorder or not. opw-1934835 --- addons/stock/models/stock_move.py | 3 ++- addons/stock/models/stock_scrap.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 21469aeed00..f3bf3bae039 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1139,7 +1139,8 @@ class StockMove(models.Model): moves_todo.mapped('move_dest_ids')._action_assign() # We don't want to create back order for scrap moves - if all(move_todo.scrapped for move_todo in moves_todo): + # Replace by a kwarg in master + if self.env.context.get('is_scrap'): return moves_todo if picking: diff --git a/addons/stock/models/stock_scrap.py b/addons/stock/models/stock_scrap.py index a6d91e1cbdb..ff8bd1aaac7 100644 --- a/addons/stock/models/stock_scrap.py +++ b/addons/stock/models/stock_scrap.py @@ -105,7 +105,8 @@ class StockScrap(models.Model): def do_scrap(self): for scrap in self: move = self.env['stock.move'].create(scrap._prepare_move_values()) - move._action_done() + # master: replace context by cancel_backorder + move.with_context(is_scrap=True)._action_done() scrap.write({'move_id': move.id, 'state': 'done'}) return True