[FIX] stock: error message for serial number needs browse on id

This commit is contained in:
Josse Colpaert
2015-07-17 13:31:07 +02:00
parent f0f09ec2d7
commit 2dead5e3cb
+3 -2
View File
@@ -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)