From b7ade94c30cfb78dbb94d01b76be17f7175e1eb2 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Thu, 6 Feb 2020 13:26:33 +0000 Subject: [PATCH] [FIX] account: correctly round amounts to compute matched percentage Before that, depending on rounding errors on floats, it was possible to end up with a matched percentage of 0.999999999 instead of 1.0 on an account move in case of full reconciliation. This could in turn cause problems with cash basis taxes, when checking what proportion of the move is reconciled. closes odoo/odoo#45094 X-original-commit: 958bee9cf9f770351fbc346a081cfe059a911b3f Signed-off-by: oco-odoo --- addons/account/models/account_move.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 101851e808c..cb04a42a920 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1867,10 +1867,11 @@ class AccountMove(models.Model): params = [self.id, self.id] self._cr.execute(query, params) total_amount, total_reconciled = self._cr.fetchone() - if float_is_zero(total_amount, precision_rounding=self.company_id.currency_id.rounding): + currency = self.company_id.currency_id + if float_is_zero(total_amount, precision_rounding=currency.rounding): return 1.0 else: - return abs(total_reconciled / total_amount) + return abs(currency.round(total_reconciled) / currency.round(total_amount)) def _get_reconciled_payments(self): """Helper used to retrieve the reconciled payments on this journal entry""" @@ -3973,7 +3974,9 @@ class AccountMoveLine(models.Model): if total_amount_currency == 0.0: matched_percentage_per_move[line.move_id.id] = 1.0 else: - matched_percentage_per_move[line.move_id.id] = total_reconciled_currency / total_amount_currency + # lines_to_consider is always non-empty when total_amount_currency is 0 + currency = lines_to_consider[0].currency_id or lines_to_consider[0].company_id.currency_id + matched_percentage_per_move[line.move_id.id] = currency.round(total_reconciled_currency) / currency.round(total_amount_currency) return matched_percentage_per_move def _get_analytic_tag_ids(self):