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.