Monday, 28 September 2020

How to override (adjust) tax through X++ code in D365 FO

 Override the tax in D365 FinOps

Today, I am going to share some activities based on Sales tax on to "Override" and "Remove the adjusted tax amount" too for a particular Sales order. 

Task# 01: To override sales tax amount in a Sales order

Here, I am going to share my experience to override the sales tax (adjust sales tax) in a Sales order.

Scenario# 1.1: To override sales tax in a sales order

Here, you just need SalesTable buffer at runtime which you need to pass to the code. I have a custom field control in the SalesTable where I am storing total actual tax amount (which I am getting from the third-party tool). 

TaxRegulation   taxRegulation;
                    SalesTotals     salesTotals = SalesTotals::construct(salesTableLocal);
        
                    salesTotals.calc();
                    taxRegulation = TaxRegulation::newTaxRegulation(salesTotals.tax());
                    taxRegulation.allocateAmount(salesTableLocal.HSTotalWebTaxAmountCur);
                    taxRegulation.saveTaxRegulation();

Scenario# 1.2: To override sales tax in a sales order

Here, the scenario is to create a Sales order and post Sales invoice along with Tax override activity too.





Task# 02: To reset Actual to Calculated sales tax amount in a Sales order

Here, I am going to share my experience on to remove adjusted sales tax amount in a Sales order.

Scenario# 2.1: To override sales tax in a sales order

Here, you just need SalesTable buffer at runtime which you need to pass to the code.

// reset actual to calculated sales tax amount.
            TaxRegulation   taxRegulation;
            SalesTotals     salesTotals = SalesTotals::construct(salesTableLocal);
            salesTotals.calc();

            taxRegulation = TaxRegulation::newTaxRegulation(salesTotals.tax(), null,salesTableLocal.TableId, salesTableLocal.RecId);
            if (taxRegulation.taxLinesExist())
            {
                taxRegulation.resetTaxRegulation();

                taxRegulation.saveTaxRegulation();
            }



Happy DAXing...


No comments:

Post a Comment