Price Including Taxes Document Level
This feature is available starting from 3.0PR17Q2. |
Introduction
After solving the issue 32265, price including taxes at document level calculation has been improved in order to avoid rounding issues.
Therefore, two main changes have been done:
- Calculate line net amount from gross amount instead from net price.
- Adjust line net amount to make sure sum of line net amounts is equals document net amount.
Calculate Line Net Amount from Gross Amount
We have changed the way we calculate the line net amount of order/invoice lines when using price including taxes in C_ORDERLINE_TRG and C_INVOICELINE_BEFORE_TRG:
In the past, we first calculated the Net Price from the Gross Amount using C_GET_NET_PRICE_FROM_GROSS function:
gross amount
net price = gross amount * ( ------------------------------------------- ) / quantity
gross amount + tax amount of gross amount
and then the Net Amount from the Net Price:
net amount = net price * quantity
Now, we first calculate the Net Amount from the Gross Amount using C_GET_NET_AMOUNT_FROM_GROSS function:
gross amount
net amount = gross amount * ( ------------------------------------------- )
gross amount + tax amount of gross amount
and then the Net Price from the Net Amount:
net price = net amount / quantity
Thus, we avoid precision loss when multiplying by quantity.
Taxes calculation at Document Level
When calculating taxes at document level, we need to take into account every order/invoice lines with the same tax to calculate the tax base and the tax amount for this tax.
This is hard to do with the current implementation of tax calculation, because logic is done in order/invoice lines triggers incrementally and we can’t have the information about other order/invoice lines at this moment due to mutating tables issue.
The followed approach to avoid this problem, is to calculate the tax bases for line and document taxes without rounding when using taxes at document level and price including taxes, and avoid precision loss when adding every order/invoice line with the same tax.
In order to follow this approach, several changes have been done:
- Create new line and document taxes without rounding the tax base when calling C_ORDERLINETAX_INSERT/C_INVOICELINETAX_INSERT from C_ORDERLINE_TRG2/C_INVOICELINE_TRG2 in case price including taxes and taxes at document level.
- In case cascade or dependant taxes at document level, we can’t calculate them by adding every line tax with the same tax, as we will get different tax base and tax amount than expected because we will be adding rounded line tax bases and amounts. We need to calculate them by adding the tax base and the tax amount of the document tax it is based on instead. This change has been done in C_ORDERLINETAX_TRG/C_INVOICELINETAX_TRG.
This change applies to both price excluding and including taxes as it was failing in both flows.
- Document gross amount and net amount calculation has been changed in case price including taxes as we need to add rounded taxes instead of round the sum of taxes. This change has been done in C_ORDERLINE_TRG2/C_INVOICELINE_TRG2 to calculate document totals by adding rounded document tax bases and amounts instead of adding line net amounts incrementally.
- When completing the order/invoice with price including taxes, we will round line and document tax bases.
Rounding and adjustment is done when calling to C_ORDERTAX_ADJUSTMENT/C_INVOICETAX_ADJUSTMENT from C_ORDER_POST1/C_INVOICE_POST.
In case taxes at document level it is also possible that we need to adjust document taxes or line net amounts. To check it, we split the document for each different group of taxes. For each subdocument we need to comply two rules:- Subdocument Gross Amount should be equals Subdocument Tax Base + Tax Amount.
In case it is not, we need to adjust the highest Tax Amount with this difference.
In case there exists cascade or dependant taxes based on the tax being adjusted, we need to propagate the adjustment to the Tax Base of all these taxes. - Subdocument Net Amount should be equals Subdocument Sum of Line Net Amounts.
In case it is not, we need to adjust the highest Line Net Amount with this difference.
We also need to propagate this adjustment to line taxes related to the line being adjusted, which is not implemented yet neither in the ERP nor in POS.
- Subdocument Gross Amount should be equals Subdocument Tax Base + Tax Amount.
- When reactivating the order/invoice with price including taxes, we will remove every line and document tax, in order to calculate again amounts and taxes without rounding and adjustments for every line and for document. This is also done when calling to C_ORDERTAX_ADJUSTMENT/C_INVOICETAX_ADJUSTMENT from C_ORDER_POST1/C_INVOICE_POST.