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