summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold Moyaux <arm@odoo.com>2019-02-14 10:06:44 +0000
committerArnold Moyaux <arm@odoo.com>2019-02-18 10:02:06 +0000
commit86cb78740b66d868131ffc808092cec19f077bee (patch)
tree401d9ae5d57127a85ac0006717e46186f4162eb5
parentf7a976584baf6e48414992d4ce3630b1f25070c3 (diff)
[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
-rw-r--r--addons/stock/models/stock_move.py3
-rw-r--r--addons/stock/models/stock_scrap.py3
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