From 300c678aded9860bf1a69bfe0ce18519bc77eee3 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 4 Apr 2017 19:10:21 +0200 Subject: [PATCH] [FIX] stock: recompute on picking assign - Create a kit (phantom BOM), composed of 2 different products A and B - Create a SO, sell a random stockable product, confirm and validate the picking. - Edit the SO, add the kit and save. Two pickings are created, one for product A and one for product B. Commit 8fe8ca99484 forces the recomputation of the stock moves, in order to be able to find a newly created picking. This should actually be done after each picking creation. opw-725929 --- addons/stock/models/stock_move.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index c7915f0fe9a..3c526a66489 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -412,15 +412,8 @@ class StockMove(models.Model): type (moves should already have them identical). Otherwise, create a new picking to assign them to. """ Picking = self.env['stock.picking'] - - # If this method is called in batch by a write on a one2many and - # at some point had to create a picking, some next iterations could - # try to find back the created picking. As we look for it by searching - # on some computed fields, we have to force a recompute, else the - # record won't be found. - self.recompute() - for move in self: + recompute = False picking = Picking.search([ ('group_id', '=', move.group_id.id), ('location_id', '=', move.location_id.id), @@ -429,8 +422,17 @@ class StockMove(models.Model): ('printed', '=', False), ('state', 'in', ['draft', 'confirmed', 'waiting', 'partially_available', 'assigned'])], limit=1) if not picking: + recompute = True picking = Picking.create(move._get_new_picking_values()) move.write({'picking_id': picking.id}) + + # If this method is called in batch by a write on a one2many and + # at some point had to create a picking, some next iterations could + # try to find back the created picking. As we look for it by searching + # on some computed fields, we have to force a recompute, else the + # record won't be found. + if recompute: + move.recompute() return True _picking_assign = assign_picking