c2c-oerpscenario team mailing list archive
-
c2c-oerpscenario team
-
Mailing list archive
-
Message #31236
[Bug 837123] [NEW] Fill inventory is incorrect
Public bug reported:
Current fill_inventory method only takes into account incoming moves (location_dest_id=location) for a specific location which is not correct:
move_ids = move_obj.search(cr, uid, [('location_dest_id','=',location),('state','=','done')], context=context)
moves in and out should be taken into account to reflect the physical
stock of the location.
I propose the following changes that solves this issue on my side:
for location in location_ids:
datas = {}
res[location] = {}
move_ids = move_obj.search(cr, uid, ['|',('location_dest_id','=',location),('location_id','=',location),('state','=','done')], context=context)#EC taking into account incoming and outgoing shipment from/to the location
for move in move_obj.browse(cr, uid, move_ids, context=context):
lot_id = move.prodlot_id.id
prod_id = move.product_id.id
#EC increase the quantity as the goods are sent to the location
if move.location_dest_id.id==location:
qty = move.product_qty
#EC decrease the quantity as the goods are sent from the location
if move.location_id.id==location:
qty = -move.product_qty
#EC strange case where dest location would be identical to origin
if move.location_id.id==location and move.location_dest_id.id==location:
qty = 0
if datas.get((prod_id, lot_id)):
qty += datas[(prod_id, lot_id)]['product_qty']
datas[(prod_id, lot_id)] = {'product_id': prod_id, 'location_id': location, 'product_qty': qty, 'product_uom': move.product_id.uom_id.id, 'prod_lot_id': lot_id}
if datas:
flag = True
res[location] = datas
if not flag:
raise osv.except_osv(_('Warning !'), _('No product in this location.'))
for stock_move in res.values():
for stock_move_details in stock_move.values():
if stock_move_details.get('product_qty') != 0:#EC We dont want to pollute the physical inventory will all O values
stock_move_details.update({'inventory_id': context['active_ids'][0]})
domain = []
if fill_inventory.set_stock_zero:
stock_move_details.update({'product_qty': 0})
for field, value in stock_move_details.items():
domain.append((field, '=', value))
line_ids = inventory_line_obj.search(cr, uid, domain, context=context)
if not line_ids:
inventory_line_obj.create(cr, uid, stock_move_details, context=context)
return {'type': 'ir.actions.act_window_close'}
** Affects: openobject-addons
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/837123
Title:
Fill inventory is incorrect
Status in OpenERP Modules (addons):
New
Bug description:
Current fill_inventory method only takes into account incoming moves (location_dest_id=location) for a specific location which is not correct:
move_ids = move_obj.search(cr, uid, [('location_dest_id','=',location),('state','=','done')], context=context)
moves in and out should be taken into account to reflect the physical
stock of the location.
I propose the following changes that solves this issue on my side:
for location in location_ids:
datas = {}
res[location] = {}
move_ids = move_obj.search(cr, uid, ['|',('location_dest_id','=',location),('location_id','=',location),('state','=','done')], context=context)#EC taking into account incoming and outgoing shipment from/to the location
for move in move_obj.browse(cr, uid, move_ids, context=context):
lot_id = move.prodlot_id.id
prod_id = move.product_id.id
#EC increase the quantity as the goods are sent to the location
if move.location_dest_id.id==location:
qty = move.product_qty
#EC decrease the quantity as the goods are sent from the location
if move.location_id.id==location:
qty = -move.product_qty
#EC strange case where dest location would be identical to origin
if move.location_id.id==location and move.location_dest_id.id==location:
qty = 0
if datas.get((prod_id, lot_id)):
qty += datas[(prod_id, lot_id)]['product_qty']
datas[(prod_id, lot_id)] = {'product_id': prod_id, 'location_id': location, 'product_qty': qty, 'product_uom': move.product_id.uom_id.id, 'prod_lot_id': lot_id}
if datas:
flag = True
res[location] = datas
if not flag:
raise osv.except_osv(_('Warning !'), _('No product in this location.'))
for stock_move in res.values():
for stock_move_details in stock_move.values():
if stock_move_details.get('product_qty') != 0:#EC We dont want to pollute the physical inventory will all O values
stock_move_details.update({'inventory_id': context['active_ids'][0]})
domain = []
if fill_inventory.set_stock_zero:
stock_move_details.update({'product_qty': 0})
for field, value in stock_move_details.items():
domain.append((field, '=', value))
line_ids = inventory_line_obj.search(cr, uid, domain, context=context)
if not line_ids:
inventory_line_obj.create(cr, uid, stock_move_details, context=context)
return {'type': 'ir.actions.act_window_close'}
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/837123/+subscriptions
Follow ups
References