Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / Which trigger to use t...
Commerce forum
Unanswered

Which trigger to use to catch discount calculation in POS before it is use din the totalAmount calculation

Posted on by 1,423

In D365F&O I have custom on Pricedisc, extending price2Amount to force the discount amount to be rounded to 2 decimals before it is used in the lineAmount calculation. We already make sure our trade agreement unit price is 2 decimals.

This was because in the DB the discount is saved with at least 5 decimals. The EDTs number of decimal fields are only for display purposes..

So when I round it to 2 decimals I use : CurrencyExchangeHelper::amount(_discAmount, _currencyCode).

Example:

Product and customer combination results in a discount of  1.224 showing on the sales order line as 1.22, which for a quantity of 5 = 6.12 .

With the unit price as 12.23 the total ends being 61.15 - 6.12 = 55.03

What the customer sees on the invoice however is:

12.23 unit price, 1.22 discount.

Then the customer does the math and ends with 61.15 - 6.10 = 55.05.

We had lots of queries for numbers not matching due to the discount showing 1.22 but in reality uses 1.224 which they can't see.

So I forced with custom that the discount amount is rounded to 2 decimals before the netAmount of the line is calculated. We already has our trade agreement unit price as 2 decimals, so no surprises for the customer when he/she does their own calculations to tee if the total amount match.

This works great now for 2 years in D365F&O.

We went live with D365 for Retail and now I have a problem that POS cart transaction is showing 6.12 for the total discount. So the customer pays the order in full, thus 55.03.

However D365F&O when calculating the totals of the order, gets 55.05 and the fulfillmentLineView in POS for the order shows the order total as 55.05 and there is a balance of 0.02 on the order. This is because GetFulfillmentLines in RetailTransactionServiceFulfillment class is using Salestotals class to determine the order total and balance and it picks up my custom to round the discount amount to 2 decimals.

I want to apply the same rounding logic to POS, but I cannot find the correct trigger/response pair to apply it to.

I tried CalculateDiscountsServiceRequest/GetPriceServiceResponse and CalculateSalesTransactionServiceRequest/CalculateSalesTransactionServiceResponse. For OnExecuting the discount fields are still zero, and on the OnExecuted, the discount amount shows already as 6.12. I have tried CalculatePricesServiceRequest as well, with no luck.

I can't use a requestHandler because it expects me to override its process, which I don't want to do. Not that I know which request to use in the handler, it is clearly not CalculateDiscountsServiceRequest, I just want to make sure that after the calculation of a discount of 1.224 per unit, that I can round it to 1.22 before it continues with the transaction totals on the cart.

 I thought CalculateDiscountsServiceRequest is that trigger, but clearly not. 

Can anybody sheds light on the trigger to use to intercept 1.224 and round it to 1.22 before it does its calculations.

  • Retha Profile Picture
    Retha 1,423 on at
    RE: Which trigger to use to catch discount calculation in POS before it is use din the totalAmount calculation

    OnExecuted of CalculateDiscountsServiceRequest already has the discount amount as 6.12, so already calculated for the quantities of each line and the discount for each line. It is too late at this point.

    Taxes are also already calculated at this point. We are making use of 3rd party software to calculate the taxes, so I can't mess with the taxes.

    I needed to be able to get to the discount after it was calculated for the customer and product before it affected the totals and taxes of the order.

    Doesn't seem that there is a trigger extension point for what I'm looking for.

    We have decided to deprecate our custom and have the sales confirmation and sales invoice journal print changed to display the 5 decimals for the discount. We are in the testing phase at the moment.

  • ToddB Profile Picture
    ToddB on at
    RE: Which trigger to use to catch discount calculation in POS before it is use din the totalAmount calculation

    Hi Retha,

    Have you tried to write a trigger for OnExecuted of CalculateDiscountsServiceRequest, and then round EffectiveAmount of each line in GetPriceServiceResponse.Transaction?

    You may also need to update fields in SalesTransaction like TotalAmount / TotalSalesAmount / SubtotalAmount / DiscountAmount>

  • Retha Profile Picture
    Retha 1,423 on at
    RE: Which trigger to use to catch discount calculation in POS before it is use din the totalAmount calculation

    Hi Todd,

    If one doesn't assign a value to the currency's rounding rule, it defaults to 0.01.  But I did add it explicitly to the currency rounding rule under Prices with the value of 0.01. It still saved the discount to the line as 1.224.  So the code totally ignore the rounding rule for discounts it seems when writing to the DB. It only applies it when displaying to the screen.

  • ToddB Profile Picture
    ToddB on at
    RE: Which trigger to use to catch discount calculation in POS before it is use din the totalAmount calculation

    Hi Retha,

    I am still looking into the extension points.

    Can you please  let me know if you have tried updating the rounding rule for prices to two decimals?

    pastedimage1617299298980v1.png

     

     

  • ToddB Profile Picture
    ToddB on at
    RE: Which trigger to use to catch discount calculation in POS before it is use din the totalAmount calculation

    HI Retha,

    I am checking to see what I can find around this, but maybe someone in the community already knows the answer.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans