Need to get the price of an item that has a sales or purchase agreement? The PriceDisc class is here to save us!

Trying to catch the best price using the PriceDisc framework

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.

Subscribe!

Receive an email when a new post is published
Author

Microsoft Dynamics 365 Finance & Operations technical architect and developer. Business Applications MVP since 2020.

4 Comments

  1. This is a helpful post, but I’m not confident it takes into account line discounts. Can you confirm?

    Thanks!

Write A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version