From 98cd83aaa0aaa1559420f4b0f06d00e1721120a6 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Fri, 18 Sep 2020 06:40:46 +0000 Subject: [PATCH] [FIX] account: Fix float division by zero in reconcile model after migration A statement line can't have a zero amount except after a migration. In that case, the residual amount of the statement line is also zero and then, the line having the suspense account has a balance of zero. When opening the bank reconciliation widget, it leads to a float division by zero because we try to compute the paid percentage of the statement line. closes odoo/odoo#58069 Task: 2341850 X-original-commit: ecc8f8be6ee09cb0fdfae0c4b35a933541d41292 Signed-off-by: oco-odoo Signed-off-by: Laurent Smet --- addons/account/models/account_bank_statement.py | 5 ++++- addons/account/models/account_reconcile_model.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 2e470c69ec8..0b7d783587b 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -772,9 +772,12 @@ class AccountBankStatementLine(models.Model): liquidity_lines, suspense_lines, other_lines = st_line._seek_for_lines() # Compute is_reconciled - if not st_line.id or suspense_lines: + if not st_line.id: # New record: The journal items are not yet there. st_line.is_reconciled = False + elif suspense_lines: + # In case of the statement line comes from an older version, it could have a residual amount of zero. + st_line.is_reconciled = all(suspense_line.reconciled for suspense_line in suspense_lines) elif st_line.currency_id.is_zero(st_line.amount): st_line.is_reconciled = True else: diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index a5899e26eef..df8c0e8fe06 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -445,6 +445,12 @@ class AccountReconcileModel(models.Model): # First associate with each rec models all the statement lines for which it is applicable lines_with_partner_per_model = defaultdict(lambda: []) for st_line in st_lines: + + # Statement lines created in old versions could have a residual amount of zero. In that case, don't try to + # match anything. + if not st_line.amount_residual: + continue + mapped_partner = (partner_map and partner_map.get(st_line.id) and self.env['res.partner'].browse(partner_map[st_line.id])) or st_line.partner_id for rec_model in available_models: