diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 996db1b6079..d5cbcd55b4f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -524,13 +524,14 @@ class stock_quant(osv.osv): # In case of serial tracking, check if the product does not exist somewhere internally already picking_type = move.picking_id and move.picking_id.picking_type_id or False - if move.product_id.tracking == 'serial' and (not picking_type or (picking_type.use_create_lots or picking_type.use_existing_lots)): + if lot_id and move.product_id.tracking == 'serial' and (not picking_type or (picking_type.use_create_lots or picking_type.use_existing_lots)): if qty != 1.0: raise UserError(_('You should only receive by the piece with the same serial number')) other_quants = self.search(cr, uid, [('product_id', '=', move.product_id.id), ('lot_id', '=', lot_id), ('qty', '>', 0.0), ('location_id.usage', '=', 'internal')], context=context) if other_quants: - raise UserError(_('The serial number %s is already in stock') % lot_id.name) + lot_name = self.pool['stock.production.lot'].browse(cr, uid, lot_id, context=context).name + raise UserError(_('The serial number %s is already in stock') % lot_name) #create the quant as superuser, because we want to restrict the creation of quant manually: we should always use this method to create quants quant_id = self.create(cr, SUPERUSER_ID, vals, context=context)