Need to get the price of an item that has a sales or purchase agreement? The PriceDisc class is here to save us!
This is one of those reference posts that I’m writing for the Adrià of the future, because it’s something I forget about a lot.
PriceDisc magic!
There’s an obsolete method, I think it was findItemPriceAgreement, to get the price, but it’s obsolete, as I’ve just said. So the easiest way to get a price is to use the PriceDisc class that replaces the obsolete method.
To use it, just instantiate a PriceDiscParameters object and call all the parm methods you need. Finally, create a PriceDisc object using the newFromPriceDiscParameters method and passing the PriceDiscParameters, and… well take a look at the code below:
public static Amount getPrice(AccountNum _accountNum,
CurrencyCode _currencyCode,
InventDim _inventDim,
ItemId _itemId,
ModuleInventPurchSales _module,
TransDate _date,
Qty _qty,
UnitId _unitId,
PriceGroupId _priceGroupId)
{
PriceDiscParameters priceDiscParameters = PriceDiscParameters::construct();
priceDiscParameters.parmAccountNum(_accountNum);
priceDiscParameters.parmCurrencyCode(_currencyCode);
priceDiscParameters.parmInventDim(_inventDim);
priceDiscParameters.parmItemId(_itemId);
priceDiscParameters.parmModuleType(_module);
priceDiscParameters.parmPriceDiscDate(_date);
priceDiscParameters.parmQty(_qty);
priceDiscParameters.parmUnitId(_unitId);
PriceDisc priceDisc = PriceDisc::newFromPriceDiscParameters(priceDiscParameters);
priceDisc.findPrice(_priceGroupId);
return priceDisc.price();
}
And that’s all. I know it’s a stupid post, but so am I and forget this kind of things.
4 Comments
This is a helpful post, but I’m not confident it takes into account line discounts. Can you confirm?
Thanks!
I’m not sure, I should check it. I don’t remember exactly if line discounts are calculated after the price has been retrieved.