[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:Laurent Smet <las@odoo.com>
Loading