diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 483115bfe64..29019385a7c 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2107,10 +2107,9 @@ class stock_inventory(osv.osv): context = {} move_obj = self.pool.get('stock.move') for inv in self.browse(cr, uid, ids, context=context): - if inv.line_ids: - for inventory_line in inv.line_ids: - if inventory_line.product_qty < 0: - raise osv.except_osv(_('Warning'),_('You cannot have a negative product quantity in an inventory line')) + for inventory_line in inv.line_ids: + if inventory_line.product_qty < 0: + raise osv.except_osv(_('Warning'),_('You cannot set a negative product quantity in an inventory line')) if not inv.move_ids: self.action_check(cr, uid, [inv.id], context=context) inv.refresh() @@ -2218,27 +2217,24 @@ class stock_inventory(osv.osv): GROUP BY product_id, location_id, lot_id, package_id, partner_id ''', args) vals = [] - negative_product_ids = [] for product_line in cr.dictfetchall(): #replace the None the dictionary by False, because falsy values are tested later on for key, value in product_line.items(): if not value: product_line[key] = False if product_line['product_qty'] < 0: - summary = 'Product: '+self.pool.get('product.product').browse(cr, uid, product_line['product_id'], context=context).name+'\n' - summary += 'Quantity: '+str(product_line['product_qty'])+'\n' - summary += 'Location: '+self.pool.get('stock.location').browse(cr, uid, product_line['location_id'], context=context).complete_name+'\n' - summary += ('Partner: '+self.pool.get('res.partner').browse(cr, uid, product_line['partner_id'],context=context).name+'\n') if product_line['partner_id'] else '' - summary += ('Lot: '+self.pool.get('stock.production.lot').browse(cr, uid, product_line['prod_lot_id'], context=context).name+'\n') if product_line['prod_lot_id'] else '' - summary += ('Package: '+self.pool.get('stock.quant.package').browse(cr, uid, product_line['package_id'], context=context).name+'\n') if product_line['package_id'] else '' - raise osv.except_osv(_('Warning'),_('This product has a negative qty, please fix it before doing an inventory\n%s' % (summary))) + summary = _('Product: ') + product_obj.browse(cr, uid, product_line['product_id'], context=context).name + '\n' + summary += _('Location: ') + location_obj.browse(cr, uid, product_line['location_id'], context=context).complete_name + '\n' + summary += (_('Partner: ') + self.pool.get('res.partner').browse(cr, uid, product_line['partner_id'], context=context).name + '\n') if product_line['partner_id'] else '' + summary += (_('Lot: ') + self.pool.get('stock.production.lot').browse(cr, uid, product_line['prod_lot_id'], context=context).name + '\n') if product_line['prod_lot_id'] else '' + summary += (_('Package: ') + self.pool.get('stock.quant.package').browse(cr, uid, product_line['package_id'], context=context).name + '\n') if product_line['package_id'] else '' + raise osv.except_osv(_('Warning'),_('This inventory line has a theoretical negative quantity, please fix it before doing an inventory\n%s' % (summary))) product_line['inventory_id'] = inventory.id product_line['th_qty'] = product_line['product_qty'] if product_line['product_id']: product = product_obj.browse(cr, uid, product_line['product_id'], context=context) product_line['product_uom_id'] = product.uom_id.id vals.append(product_line) - return vals class stock_inventory_line(osv.osv):