diff --git a/account_reconcile_model_oca/models/account_reconcile_model.py b/account_reconcile_model_oca/models/account_reconcile_model.py index 9558b16b..1fb94b5b 100644 --- a/account_reconcile_model_oca/models/account_reconcile_model.py +++ b/account_reconcile_model_oca/models/account_reconcile_model.py @@ -422,12 +422,17 @@ class AccountReconcileModel(models.Model): ) """ # noqa: E501 all_params += where_params + + enabled_matches = [] + if self.match_text_location_label: + enabled_matches.append(("account_move_line", "name")) + if self.match_text_location_note: + enabled_matches.append(("account_move_line__move_id", "name")) + if self.match_text_location_reference: + enabled_matches.append(("account_move_line__move_id", "ref")) + if numerical_tokens: - for table_alias, field in ( - ("account_move_line", "name"), - ("account_move_line__move_id", "name"), - ("account_move_line__move_id", "ref"), - ): + for table_alias, field in enabled_matches: sub_queries.append( rf""" SELECT @@ -451,11 +456,7 @@ class AccountReconcileModel(models.Model): ) if exact_tokens: - for table_alias, field in ( - ("account_move_line", "name"), - ("account_move_line__move_id", "name"), - ("account_move_line__move_id", "ref"), - ): + for table_alias, field in enabled_matches: sub_queries.append( rf""" SELECT diff --git a/account_reconcile_model_oca/tests/test_reconciliation_match.py b/account_reconcile_model_oca/tests/test_reconciliation_match.py index e23a657e..ae5752b7 100644 --- a/account_reconcile_model_oca/tests/test_reconciliation_match.py +++ b/account_reconcile_model_oca/tests/test_reconciliation_match.py @@ -77,6 +77,8 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): "match_nature": "both", "match_same_currency": True, "allow_payment_tolerance": True, + "match_text_location_note": True, + "match_text_location_reference": True, "payment_tolerance_type": "percentage", "payment_tolerance_param": 0.0, "match_partner": True, @@ -421,7 +423,11 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): @freeze_time("2019-01-01") def test_zero_payment_tolerance(self): - rule = self._create_reconcile_model(line_ids=[{}]) + rule = self._create_reconcile_model( + line_ids=[{}], + match_text_location_reference=True, + match_text_location_note=True, + ) for inv_type, bsl_sign in (("out_invoice", 1), ("in_invoice", -1)): invl = self._create_invoice_line( @@ -774,24 +780,29 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): self.rule_1.sequence = 2 self.rule_1.auto_reconcile = True self.rule_1.payment_tolerance_param = 10.0 - self.rule_1.match_text_location_label = False self.rule_2.sequence = 1 self.rule_2.match_partner_ids |= self.partner_2 self.rule_2.auto_reconcile = True self._check_statement_matching( - self.rule_1 + self.rule_2, + self.rule_1, { self.bank_line_1: { "amls": self.invoice_line_1, "model": self.rule_1, "auto_reconcile": True, }, + }, + ) + rule_3 = self.rule_1.copy({"match_text_location_label": False}) + self._check_statement_matching( + self.rule_2 + rule_3, + { self.bank_line_2: { "amls": self.invoice_line_1 + self.invoice_line_2 + self.invoice_line_3, - "model": self.rule_1, + "model": rule_3, }, self.cash_line_1: { "model": self.rule_2, @@ -811,7 +822,6 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): self.rule_1.allow_payment_tolerance = False self.rule_1.auto_reconcile = True self.rule_1.line_ids = [(5, 0, 0)] - self.rule_1.match_text_location_label = False self._check_statement_matching( self.rule_1, @@ -821,11 +831,17 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): "model": self.rule_1, "auto_reconcile": True, }, + }, + ) + rule_3 = self.rule_1.copy({"match_text_location_label": False}) + self._check_statement_matching( + rule_3, + { self.bank_line_2: { "amls": self.invoice_line_1 + self.invoice_line_2 + self.invoice_line_3, - "model": self.rule_1, + "model": rule_3, }, }, ) @@ -1382,9 +1398,8 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): rule = self._create_reconcile_model( match_partner=False, allow_payment_tolerance=False, - match_text_location_label=False, - match_text_location_reference=False, - match_text_location_note=False, + match_text_location_reference=True, + match_text_location_note=True, ) st_line = self._create_st_line(amount=1000, partner_id=False) invoice = self.env["account.move"].create( @@ -1423,8 +1438,10 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): {"amls": term_line, "model": rule}, ) - # No matching if other checkbox is checked. - rule.match_text_location_note = True + # No matching if checkbox is unchecked. + rule.match_text_location_label = False + rule.match_text_location_reference = False + rule.match_text_location_note = False self.assertDictEqual( rule._apply_rules(st_line, None), {},