Hi Everyone,
Need urgent help on below issue
I am trying to fetch average unit cost of Item through X code which is available on below path,
Released products > Manage costs > Cost objects
Below code I found on one of the blogs, but somehow it doesn't give perfect result for all transactions.
public static void main(Args _args)
{
ItemId _itemId = "2108050";
InventSum inventSum;
Amount avgUnitCost;
InventDim inventDim;
InventDim inventDimFind;
InventCostPriceCache inventCostPriceCache;
UnitOfMeasureConverter_Product productUnitConverter;
UnitOfMeasureRecId fromUnitMeasureRecId;
UnitOfMeasureRecId toUnitMeasureRecId;
InventTable inventTable;
Amount costPrice, convertValue;
select firstonly * from inventSum where inventSum.ItemId == _itemId
join inventDim;
if(!inventSum.InventDimId)
{
inventDimFind = InventDim::findDim(inventDim);
if(inventDimFind.inventDimId)
{
inventSum.InventDimId = inventDimFind.inventDimId;
}
}
inventCostPriceCache = InventCostPriceCache::construct();
inventTable = inventSum.inventTable();
fromUnitMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.salesUnitId()).RecId;
toUnitMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.inventUnitId()).RecId;
productUnitConverter = UnitOfMeasureConverter_Product::construct();
productUnitConverter.parmProduct(inventTable.Product);
productUnitConverter.parmFromUnitOfMeasure(fromUnitMeasureRecId);
productUnitConverter.parmToUnitOfMeasure(toUnitMeasureRecId);
productUnitConverter.parmRoundAbsoluteValue(NoYes::Yes);
productUnitConverter.parmApplyRounding(NoYes::Yes);
costPrice = inventCostPriceCache.costPricePcs(inventSum, inventDim);
convertValue = productUnitConverter.convertValue(1);
info(strFmt("costPrice %1, convertValue%2", costPrice, convertValue));
avgUnitCost = costPrice * convertValue;
info(strFmt("avgUnitCost %1", avgUnitCost));
}
Please suggest solution on this.
I want to fetch the Average unit cost Site wise. Please refer below highlighted values.
