Wednesday, May 13, 2015

Get the running average cost of an item

This is how you fetch an item's running average cost. In below case both the warehouse and site are same as the retail store ID. You set the inventDim and use inventOnHand class that does the trick.

 private CostPrice getAverageCost(RetailStoreId _storeId, ItemId  _itemdId)  
   InventDim        inventDim;  
   InventDimParm      inventDimParm;  
   InventOnHand      inventOnHand;  
   inventDim.InventLocationId = _storeId;  
   inventDim.InventSiteId   = _storeId;  
   inventDim = InventDim::findOrCreate(inventDim);  
   inventOnHand = InventOnHand::newItemDim(_itemdId, inventDim, inventDimParm);  
   return inventOnHand.costPricePcs();  

This is the same cost that you see on On-hand form for an item (Cost price field at the bottom), for a particular warehouse. For weighted average model group, cost price = Financial cost amount / Posted qty.

No comments:

Post a Comment