summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Snauwaert <csn@openerp.com>2014-01-24 14:56:25 +0100
committerCedric Snauwaert <csn@openerp.com>2014-01-24 14:56:25 +0100
commit1f818db2ffd4fd2ceea63f48447bd0656d22e804 (patch)
treea0b7f41e064a687b4803ecc3417df0b3ed6f14a0
parent783a0d52adbf5a2d079d6659462edfe5c5e13019 (diff)
[FIX]wizard stock_change_product_qty: when changing qty of a product, the way the inventory was used was wrong
bzr revid: csn@openerp.com-20140124135625-8y5ehlsbexp3iyqm
-rw-r--r--addons/stock/wizard/stock_change_product_qty.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py
index 7e86c07b28f..9a2d7bb5d23 100644
--- a/addons/stock/wizard/stock_change_product_qty.py
+++ b/addons/stock/wizard/stock_change_product_qty.py
@@ -74,25 +74,33 @@ class stock_change_product_qty(osv.osv_memory):
rec_id = context and context.get('active_id', False)
assert rec_id, _('Active ID is not set in Context')
- inventry_obj = self.pool.get('stock.inventory')
- inventry_line_obj = self.pool.get('stock.inventory.line')
+ inventory_obj = self.pool.get('stock.inventory')
+ inventory_line_obj = self.pool.get('stock.inventory.line')
prod_obj_pool = self.pool.get('product.product')
res_original = prod_obj_pool.browse(cr, uid, rec_id, context=context)
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 = inventry_obj.create(cr , uid, {'name': _('INV: %s') % tools.ustr(res_original.name)}, 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
- }
- inventry_line_obj.create(cr , uid, line_data, context=context)
- inventry_obj.action_done(cr, uid, [inventory_id], 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}, 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)
+ #validate inventory
+ inventory_obj.action_done(cr, uid, [inventory_id], context=context)
return {}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: