Skip to content
Snippets Groups Projects
Commit 60f413dc authored by Nshimiyimana Séna's avatar Nshimiyimana Séna Committed by Laurent Smet
Browse files

[FIX] account: fix cash rounding when rounding method is set to global

- install Accounting
- in the settings, set `Rounding Method` to `Round Globally` and
  activate `Cash Rounding`
- create a cash rounding with the `half-up` method, a `Add a rounding
  line` strategy and a rounding precision of  `0.05`
- create a 7.7% sales tax
- create an invoice and in the `Other Info` tab, set `Cash Rounding
  Method` to the rounding you just created
- add an invoice line with a price of 295.00 and the 7.7% tax

You should see that the generated rounding line is not correct.
The total is 317.72; so we expect the rounding line to have a price of
`-0.02`, to respect the cash rounding.

The cash rounding computation is initiated here:
https://github.com/odoo/odoo/blob/1dcd071b27779e7d6d8f536c7dce7002d27212ba/addons/account/models/account_move.py#L944

However, `total_amount_currency` is not rounded. This introduces
floating imprecision that end up messing with the calculation here:
https://github.com/odoo/odoo/blob/563752358d233d4fc9cf1d7e7abd0b1656dc82c1/addons/account/models/account_cash_rounding.py#L53



If we take the example given in the reproduction steps, the values in
that line will be as follows:
- `amout = -317.71500000000003`
- `self.round(amount) = -317.70000000000005`
- `difference = self.round(amount) - amount = 0.014999999999986358`

`difference` is then rounded to 0.01 which not correct.

This issue does not happen starting v16.0, as `total_amount_currency`
is already rounded when `_compute_cash_rounding` is called.

opw-3133291

closes odoo/odoo#113500

Signed-off-by: default avatarLaurent Smet <las@odoo.com>
parent a4b4b6b9
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment