# How Price Including Taxes are Calculated

## Introduction

Since the availability of the "**Price Lists Including Taxes**" feature, there has been some doubts on how net prices/amounts and tax amounts are calculated.

This how is aimed to explain these calculations in a simple way.

The calculation can be split into two steps:

- First one is to calculate the
**Net Price**based on a given**Gross Price**and then the corresponding**Tax Rate** - Second one is to calculated the
**Tax Amount**based on the newly calculated**Net Price**which then needs to be adjusted so the**Net Amount**plus the**Tax Amount**is equal to the**Gross Amount**.

## Net Price Calculation

In *Openbravo* cascade taxes calculation is supported. This means that when the *Net Price* is being calculated we might not have a single rate to work with, but a relation of different tax rates.

Cascade taxes make the calculation of a net price from a given a gross price a bit more difficult. You would normally divide the gross price by the rate to get the net price, but the rate might not be a unique one, in other words it might not be available therefore it has to be calculated.

To calculate the tax rate we need to calculate the tax amount that corresponds to the gross price. If we divide that tax amount by the gross price we get the tax rate.

```
```

```
``` tax amount of gross price
tax rate = -------------------------
gross price

```
```

Having the tax rate we can calculate the net price:

```
```

```
``` gross price
net price = -------------
tax rate

```
```

If we substitute the tax rate by the previous formula and simplify it we get:

```
```

```
``` gross price
net price = gross price * ( -------------------------- )
gross price + tax amount

```
```

This method returns the exact result, but its implementation requires to round the calculated tax amount.

In former Openbravo MPs this was rounded to the *Price Precision* of the currency, thus having a higher price precision was recommended.

After solving the issue 24378, a 50 decimals precision is used. If the price precision is higher than that, the price precision is used.

To help reducing the impact of this rounding issue instead of using the price, the total gross amount is used to calculate the net amount which once divided by the quantity, allow us to obtain the net price. The formula used then is:

```
```

```
``` gross amount
net price = gross amount * ( ------------------------------------------- ) / quantity
gross amount + tax amount of gross amount

```
```

## Taxes Calculation

Once the net price is calculated it is time to calculate the final tax amount of the Order or the Invoice.

When taxes are calculated we also need to consider different possible configurations. Tax amounts might be rounded either at line or document level.

Besides, a single line might have tax amounts of different tax rates, if cascade tax rates are being used. So subtracting the net amount to the gross amount is not a valid option.

As the net prices are known, the standard methods to calculate the tax amounts based on net prices are used. However, the calculated net price has to be rounded to the price precision of the currency. This means that the sum of the tax amounts and the net amount might not be equal to the total gross amount. The difference needs to be adjusted in the tax amounts by adding or subtracting the difference to the higher tax amount so the final sum is correct.

Tax Example | Gross Amt | Net Amt | Rounded Net | Tax Amount | Adjusted Tax |
---|---|---|---|---|---|

Simple 21% | 1.53 | 1.26446 | 1.26 | 0.26 | 0.27 |

Simple 21% | 1.21 | 1.00 | 1.00 | 0.21 | 0.21 |

Simple 21% | 1.64 | 1.35537 | 1.36 | 0.29 | 0.28 |

6.25% + 1% | 1.56 | 1.454545 | 1.45 | 0.09+0.01 | 0.10+0.01 |

6.25% + 1% | 1.61 | 1.501165 | 1.50 | 0.10+0.01 | 0.10+0.01 |

6.25% + 1% | 1.65 | 1.538461 | 1.54 | 0.10+.0.02 | 0.09+0.02 |