Hi All,
In new D365FO the UnitOfMeasureConverter::convert() method is depreciated so we need to use EcoResProductUnitConverter method for unit conversion.
Please refer below code, the EcoResProductUnitConverter::convertGivenUnitSymbolsForReleasedProduct method will convert the quantity from invent quantity to sales quantity
public PurchQty convertSalesQty(ItemId _itemId,InventDimId _inventDimId, Qty _qty, SalesUnit _salesUnit)
{
SalesQty salesQty;
InventUnitId inventUnit;
inventUnit = InventTableModule::find(_itemId,ModuleInventPurchSales::Invent).UnitId;
//salesQty = UnitOfMeasureConverter::convert(_qty
// , UnitOfMeasure::unitOfMeasureIdBySymbol(inventUnit)
// , UnitOfMeasure::unitOfMeasureIdBySymbol(_salesUnit)
// , NoYes::Yes
// , InventTable::itemProduct(_itemId));
In AX2012 we used UnitOfMeasureConverter::convert() method to convert the unit from invent to sales. But if we use same method in D365Fo we will receive the best practices error like the method UnitOfMeasureConverter::convert() is depreciated use EcoResProductUnitConverter class.
Please find below how to use EcoResProductUnitConverter class in D365FO to convert unit.
salesQty = EcoResProductUnitConverter::convertGivenUnitSymbolsForReleasedProduct(_itemId
, _inventDimId
, _qty
, inventUnit
, _salesUnit
, NoYes::Yes
, NoYes::No);
return salesQty;
}
In new D365FO the UnitOfMeasureConverter::convert() method is depreciated so we need to use EcoResProductUnitConverter method for unit conversion.
Please refer below code, the EcoResProductUnitConverter::convertGivenUnitSymbolsForReleasedProduct method will convert the quantity from invent quantity to sales quantity
public PurchQty convertSalesQty(ItemId _itemId,InventDimId _inventDimId, Qty _qty, SalesUnit _salesUnit)
{
SalesQty salesQty;
InventUnitId inventUnit;
inventUnit = InventTableModule::find(_itemId,ModuleInventPurchSales::Invent).UnitId;
//salesQty = UnitOfMeasureConverter::convert(_qty
// , UnitOfMeasure::unitOfMeasureIdBySymbol(inventUnit)
// , UnitOfMeasure::unitOfMeasureIdBySymbol(_salesUnit)
// , NoYes::Yes
// , InventTable::itemProduct(_itemId));
In AX2012 we used UnitOfMeasureConverter::convert() method to convert the unit from invent to sales. But if we use same method in D365Fo we will receive the best practices error like the method UnitOfMeasureConverter::convert() is depreciated use EcoResProductUnitConverter class.
Please find below how to use EcoResProductUnitConverter class in D365FO to convert unit.
salesQty = EcoResProductUnitConverter::convertGivenUnitSymbolsForReleasedProduct(_itemId
, _inventDimId
, _qty
, inventUnit
, _salesUnit
, NoYes::Yes
, NoYes::No);
return salesQty;
}
//Refer smmSalesCustItemStatisticsDP class
EcoResProductUnitConverter productUnitConverter = EcoResProductUnitConverter::newGivenUnitSymbolsForReleasedProduct(
_itemId,
_inventDimId,
_unitFrom,
unitInvent,
NoYes::Yes);
Thank you for your help, it worked fine! Greetings.
ReplyDelete