[FIX]product qty wizard adjustement: take into account lot id and should not prepare...
authorCedric Snauwaert <csn@openerp.com>
Thu, 30 Jan 2014 13:44:57 +0000 (14:44 +0100)
committerCedric Snauwaert <csn@openerp.com>
Thu, 30 Jan 2014 13:44:57 +0000 (14:44 +0100)
bzr revid: csn@openerp.com-20140130134457-6ukdbv0lyz98tkej

addons/stock/wizard/stock_change_product_qty.py

index 9a2d7bb..9b6fa8f 100644 (file)
@@ -82,23 +82,16 @@ class stock_change_product_qty(osv.osv_memory):
         for data in self.browse(cr, uid, ids, context=context):
             if data.new_quantity < 0:
                 raise osv.except_osv(_('Warning!'), _('Quantity cannot be negative.'))
-            inventory_id = inventory_obj.create(cr , uid, {'name': _('INV: %s') % tools.ustr(res_original.name), 'product_id': rec_id, 'location_id': data.location_id.id}, context=context)
-            #perform an inventory for this particular product in this particular location
-            inventory_obj.prepare_inventory(cr, uid, [inventory_id], context=context)
-            #if we've got an inventory line, change it's qty, else create new line
-            line_ids = inventory_obj.browse(cr, uid, inventory_id, context=context).line_ids or False
-            if line_ids:
-                inventory_line_obj.write(cr, uid, line_ids[0].id, {'product_qty': data.new_quantity}, context=context)
-            else:
-                line_data ={
-                    'inventory_id' : inventory_id,
-                    'product_qty' : data.new_quantity,
-                    'location_id' : data.location_id.id,
-                    'product_id' : rec_id,
-                    'product_uom_id' : res_original.uom_id.id,
-                    'prod_lot_id' : data.lot_id.id
-                }
-                inventory_line_obj.create(cr , uid, line_data, context=context)
+            inventory_id = inventory_obj.create(cr , uid, {'name': _('INV: %s') % tools.ustr(res_original.name), 'product_id': rec_id, 'location_id': data.location_id.id, 'lot_id': data.lot_id.id if data.lot_id else False}, context=context)
+            line_data ={
+                'inventory_id' : inventory_id,
+                'product_qty' : data.new_quantity,
+                'location_id' : data.location_id.id,
+                'product_id' : rec_id,
+                'product_uom_id' : res_original.uom_id.id,
+                'prod_lot_id' : data.lot_id.id if data.lot_id else False
+            }
+            inventory_line_obj.create(cr , uid, line_data, context=context)
             #validate inventory
             inventory_obj.action_done(cr, uid, [inventory_id], context=context)
         return {}