diff --git a/account_reconcile_model_oca/models/account_reconcile_model.py b/account_reconcile_model_oca/models/account_reconcile_model.py index c7c1c6e1..c691391a 100644 --- a/account_reconcile_model_oca/models/account_reconcile_model.py +++ b/account_reconcile_model_oca/models/account_reconcile_model.py @@ -481,6 +481,15 @@ class AccountReconcileModel(models.Model): "allow_auto_reconcile": True, "amls": self.env["account.move.line"].browse(candidate_ids), } + elif ( + self.match_text_location_label + or self.match_text_location_note + or self.match_text_location_reference + ): + # In the case any of the Label, Note or Reference matching rule has been + # toggled, and the query didn't return + # any candidates, the model should not try to mount another aml instead. + return if not partner: st_line_currency = ( diff --git a/account_reconcile_model_oca/tests/test_reconciliation_match.py b/account_reconcile_model_oca/tests/test_reconciliation_match.py index 05af3aa4..e23a657e 100644 --- a/account_reconcile_model_oca/tests/test_reconciliation_match.py +++ b/account_reconcile_model_oca/tests/test_reconciliation_match.py @@ -284,6 +284,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): def test_matching_fields(self): # Check without restriction. + self.rule_1.match_text_location_label = False self._check_statement_matching( self.rule_1, { @@ -299,6 +300,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) def test_matching_fields_match_journal_ids(self): + self.rule_1.match_text_location_label = False self.rule_1.match_journal_ids |= self.cash_line_1.journal_id self._check_statement_matching( self.rule_1, @@ -310,6 +312,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) def test_matching_fields_match_nature(self): + self.rule_1.match_text_location_label = False self.rule_1.match_nature = "amount_received" self._check_statement_matching( self.rule_1, @@ -335,6 +338,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) def test_matching_fields_match_amount(self): + self.rule_1.match_text_location_label = False self.rule_1.match_amount = "lower" self.rule_1.match_amount_max = 150 self._check_statement_matching( @@ -378,6 +382,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) def test_matching_fields_match_label(self): + self.rule_1.match_text_location_label = False self.rule_1.match_label = "contains" self.rule_1.match_label_param = "yyyyy" self._check_statement_matching( @@ -424,21 +429,27 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) # Exact matching. - st_line = self._create_st_line(amount=bsl_sign * 1000.0) + st_line = self._create_st_line( + amount=bsl_sign * 1000.0, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {"amls": invl, "model": rule}}, ) # No matching because there is no tolerance. - st_line = self._create_st_line(amount=bsl_sign * 990.0) + st_line = self._create_st_line( + amount=bsl_sign * 990.0, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {}}, ) # The payment amount is higher than the invoice one. - st_line = self._create_st_line(amount=bsl_sign * 1010.0) + st_line = self._create_st_line( + amount=bsl_sign * 1010.0, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {"amls": invl, "model": rule}}, @@ -461,7 +472,9 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) # No matching because there is no tolerance. - st_line = self._create_st_line(amount=bsl_sign * 990.0) + st_line = self._create_st_line( + amount=bsl_sign * 990.0, payment_ref="123456" + ) self._check_statement_matching( rule, {st_line: {}}, @@ -490,7 +503,9 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) # No matching because there is no enough tolerance. - st_line = self._create_st_line(amount=bsl_sign * 990.0) + st_line = self._create_st_line( + amount=bsl_sign * 990.0, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {}}, @@ -499,7 +514,9 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): # The payment amount is higher than the invoice one. # However, since the invoice amount is lower than the payment amount, # the tolerance is not checked and the invoice line is matched. - st_line = self._create_st_line(amount=bsl_sign * 1010.0) + st_line = self._create_st_line( + amount=bsl_sign * 1010.0, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {"amls": invl, "model": rule}}, @@ -518,7 +535,9 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) # Enough tolerance to match the invoice line. - st_line = self._create_st_line(amount=bsl_sign * 1185.80) + st_line = self._create_st_line( + amount=bsl_sign * 1185.80, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {"amls": invl, "model": rule, "status": "write_off"}}, @@ -527,7 +546,9 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): # The payment amount is higher than the invoice one. # However, since the invoice amount is lower than the payment amount, # the tolerance is not checked and the invoice line is matched. - st_line = self._create_st_line(amount=bsl_sign * 1234.20) + st_line = self._create_st_line( + amount=bsl_sign * 1234.20, payment_ref=invl.name + ) self._check_statement_matching( rule, {st_line: {"amls": invl, "model": rule}}, @@ -576,7 +597,9 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): invl = self._create_invoice_line( 990.0, self.partner_a, inv_type, inv_date="2019-01-01" ) - st_line = self._create_st_line(amount=bsl_sign * 1000) + st_line = self._create_st_line( + amount=bsl_sign * 1000, payment_ref=invl.name + ) # Partial reconciliation. self._check_statement_matching( @@ -656,6 +679,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): ) def test_matching_fields_match_partner_category_ids(self): + self.rule_1.match_text_location_label = False test_category = self.env["res.partner.category"].create( {"name": "Consulting Services"} ) @@ -676,6 +700,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): def test_mixin_rules(self): """Test usage of rules together.""" + self.rule_1.match_text_location_label = False # rule_1 is used before rule_2. self.rule_1.sequence = 1 self.rule_2.sequence = 2 @@ -749,6 +774,7 @@ 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 @@ -785,6 +811,7 @@ 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, @@ -952,6 +979,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): move_reversed = move._reverse_moves() self.assertTrue(move_reversed.exists()) + self.rule_1.match_text_location_label = False self.bank_line_1.write( { "payment_ref": "8", @@ -993,7 +1021,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): "partner_id": partner.id, "foreign_currency_id": currency_statement.id, "amount_currency": 100, - "payment_ref": "test", + "payment_ref": invoice_line.name, } ) self._check_statement_matching( @@ -1127,6 +1155,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): "match_same_currency": False, "company_id": self.company_data["company"].id, "past_months_limit": False, + "match_text_location_label": False, } ) @@ -1303,6 +1332,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): 200 should be proposed. """ self.rule_1.allow_payment_tolerance = False + self.rule_1.match_text_location_label = False self.bank_line_2.amount = 250 self.bank_line_1.partner_id = None @@ -1325,6 +1355,7 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon): other ones are disregarded. """ self.rule_1.allow_payment_tolerance = False + self.rule_1.match_text_location_label = False self.bank_line_2.amount = 300 self.bank_line_1.partner_id = None