From 5800f20ccf63ef8482d1460f46c8c5fe30eac822 Mon Sep 17 00:00:00 2001 From: jbw Date: Mon, 17 May 2021 11:26:15 +0000 Subject: [FIX] account: fix reconcile rule percentage calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In https://github.com/odoo/odoo/pull/52529/commits/078a3a0f760ff24d02070a343f28d2249a8b5ba7#diff-c217a13a40a3cc27dc516b899793abecfac8cab9a42fed407d4776bcbc9de9a8R812 the way the percentage is calculated is changed. This implies that a reconciliation rule allowing a 90% matching amount will not allow to reconcile a 90$ bank statement with a 100$ invoice (as it will calculate the % as 88.89%, not meeting the required 90 %) After cited commit: invoice 200, bank statement 180: (|-180| - |20|) / |-180| * 100 = 88.89% invoice 200, bank statement 220: (|-220| - |-20|) / |-220| * 100 = 90.91% credit note 200, bank statement -180: (|180| - |-20|) / |180| * 100 = 88.89% credit note 200, bank statement -220: (|220| - |20|) / |220| * 100 = 90.91% Now: invoice 200, bank statement 180: 100 - |20| / |(-180 - 20)| * 100 = 90% invoice 200, bank statement 220: 100 - |-20| / |(-220 - -20)| * 100 = 90% credit note 200, bank statement -180: 100 - |-20| / |(180 - -20)| * 100 = 90% credit note 200, bank statement -220: 100 - |20| / |(220 - 20)| * 100 = 90% closes odoo/odoo#70948 Task: 2427089 Signed-off-by: William André (wan) --- addons/account/models/account_reconcile_model.py | 3 +- .../tests/test_reconciliation_matching_rules.py | 38 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 4b866bcbbb6..5a7a99f1ed8 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -884,8 +884,7 @@ class AccountReconcileModel(models.Model): # Statement line amount is equal to the total residual. if line_currency.is_zero(line_residual_after_reconciliation): return True - - reconciled_percentage = (abs(line_residual) - abs(line_residual_after_reconciliation)) / abs(line_residual) * 100 + reconciled_percentage = 100 - abs(line_residual_after_reconciliation) / abs(line_residual - line_residual_after_reconciliation) * 100 return reconciled_percentage >= self.match_total_amount_param def _filter_candidates(self, candidates, aml_ids_to_exclude, reconciled_amls_ids): diff --git a/addons/account/tests/test_reconciliation_matching_rules.py b/addons/account/tests/test_reconciliation_matching_rules.py index c00fe13cbbd..ed01c56526b 100644 --- a/addons/account/tests/test_reconciliation_matching_rules.py +++ b/addons/account/tests/test_reconciliation_matching_rules.py @@ -350,7 +350,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): def test_matching_fields_match_total_amount(self): # Check match_total_amount: line amount >= total residual amount. self.rule_1.match_total_amount_param = 90.0 - self.bank_line_1.amount += 5 + self.bank_line_1.amount += 10 self._check_statement_matching(self.rule_1, { self.bank_line_1.id: {'aml_ids': [self.invoice_line_1.id], 'model': self.rule_1, 'status': 'write_off', 'partner': self.bank_line_1.partner_id}, self.bank_line_2.id: {'aml_ids': [ @@ -361,11 +361,11 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): self.cash_line_1.id: {'aml_ids': [self.invoice_line_4.id], 'model': self.rule_1, 'partner': self.cash_line_1.partner_id}, }) self.rule_1.match_total_amount_param = 100.0 - self.bank_line_1.amount -= 5 + self.bank_line_1.amount -= 10 # Check match_total_amount: line amount <= total residual amount. self.rule_1.match_total_amount_param = 90.0 - self.bank_line_1.amount -= 5 + self.bank_line_1.amount -= 10 self._check_statement_matching(self.rule_1, { self.bank_line_1.id: {'aml_ids': [self.invoice_line_1.id], 'model': self.rule_1, 'status': 'write_off', 'partner': self.bank_line_1.partner_id}, self.bank_line_2.id: {'aml_ids': [ @@ -376,7 +376,37 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): self.cash_line_1.id: {'aml_ids': [self.invoice_line_4.id], 'model': self.rule_1, 'partner': self.cash_line_1.partner_id}, }) self.rule_1.match_total_amount_param = 100.0 - self.bank_line_1.amount += 5 + self.bank_line_1.amount += 10 + + # Check match_total_amount: line amount >= total residual amount, match_total_amount_param just not matched. + self.rule_1.match_total_amount_param = 90.0 + self.bank_line_1.amount += 10.01 + self._check_statement_matching(self.rule_1, { + self.bank_line_1.id: {'aml_ids': []}, + self.bank_line_2.id: {'aml_ids': [ + self.invoice_line_1.id, + self.invoice_line_2.id, + self.invoice_line_3.id, + ], 'model': self.rule_1, 'partner': self.bank_line_2.partner_id}, + self.cash_line_1.id: {'aml_ids': [self.invoice_line_4.id], 'model': self.rule_1, 'partner': self.cash_line_1.partner_id}, + }) + self.rule_1.match_total_amount_param = 100.0 + self.bank_line_1.amount -= 10.01 + + # Check match_total_amount: line amount <= total residual amount, match_total_amount_param just not matched. + self.rule_1.match_total_amount_param = 90.0 + self.bank_line_1.amount -= 10.01 + self._check_statement_matching(self.rule_1, { + self.bank_line_1.id: {'aml_ids': []}, + self.bank_line_2.id: {'aml_ids': [ + self.invoice_line_1.id, + self.invoice_line_2.id, + self.invoice_line_3.id, + ], 'model': self.rule_1, 'partner': self.bank_line_2.partner_id}, + self.cash_line_1.id: {'aml_ids': [self.invoice_line_4.id], 'model': self.rule_1, 'partner': self.cash_line_1.partner_id}, + }) + self.rule_1.match_total_amount_param = 100.0 + self.bank_line_1.amount += 10.01 def test_matching_fields_match_partner_category_ids(self): test_category = self.env['res.partner.category'].create({'name': 'Consulting Services'}) -- cgit v1.2.3