[FIX] account_reconcile_model_oca: Suggest amls candidates correctly filtering as defined in the reconciliation model

Reconciliation model use case:
- No auto-validate
- No Match Invoice/bill fields set.

Expected result:
- The amls suggested should be as expected, i.e., do not filter for data that
is not defined in the reconciliation model.

TT52146

Related to 1db826b3c4
pull/819/head
Víctor Martínez 2025-03-31 09:52:19 +02:00
parent f9078dc573
commit f7e30d1401
2 changed files with 39 additions and 21 deletions

View File

@ -422,12 +422,17 @@ class AccountReconcileModel(models.Model):
) )
""" # noqa: E501 """ # noqa: E501
all_params += where_params 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: if numerical_tokens:
for table_alias, field in ( for table_alias, field in enabled_matches:
("account_move_line", "name"),
("account_move_line__move_id", "name"),
("account_move_line__move_id", "ref"),
):
sub_queries.append( sub_queries.append(
rf""" rf"""
SELECT SELECT
@ -451,11 +456,7 @@ class AccountReconcileModel(models.Model):
) )
if exact_tokens: if exact_tokens:
for table_alias, field in ( for table_alias, field in enabled_matches:
("account_move_line", "name"),
("account_move_line__move_id", "name"),
("account_move_line__move_id", "ref"),
):
sub_queries.append( sub_queries.append(
rf""" rf"""
SELECT SELECT

View File

@ -77,6 +77,8 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
"match_nature": "both", "match_nature": "both",
"match_same_currency": True, "match_same_currency": True,
"allow_payment_tolerance": True, "allow_payment_tolerance": True,
"match_text_location_note": True,
"match_text_location_reference": True,
"payment_tolerance_type": "percentage", "payment_tolerance_type": "percentage",
"payment_tolerance_param": 0.0, "payment_tolerance_param": 0.0,
"match_partner": True, "match_partner": True,
@ -421,7 +423,11 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
@freeze_time("2019-01-01") @freeze_time("2019-01-01")
def test_zero_payment_tolerance(self): 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)): for inv_type, bsl_sign in (("out_invoice", 1), ("in_invoice", -1)):
invl = self._create_invoice_line( invl = self._create_invoice_line(
@ -774,24 +780,29 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
self.rule_1.sequence = 2 self.rule_1.sequence = 2
self.rule_1.auto_reconcile = True self.rule_1.auto_reconcile = True
self.rule_1.payment_tolerance_param = 10.0 self.rule_1.payment_tolerance_param = 10.0
self.rule_1.match_text_location_label = False
self.rule_2.sequence = 1 self.rule_2.sequence = 1
self.rule_2.match_partner_ids |= self.partner_2 self.rule_2.match_partner_ids |= self.partner_2
self.rule_2.auto_reconcile = True self.rule_2.auto_reconcile = True
self._check_statement_matching( self._check_statement_matching(
self.rule_1 + self.rule_2, self.rule_1,
{ {
self.bank_line_1: { self.bank_line_1: {
"amls": self.invoice_line_1, "amls": self.invoice_line_1,
"model": self.rule_1, "model": self.rule_1,
"auto_reconcile": True, "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: { self.bank_line_2: {
"amls": self.invoice_line_1 "amls": self.invoice_line_1
+ self.invoice_line_2 + self.invoice_line_2
+ self.invoice_line_3, + self.invoice_line_3,
"model": self.rule_1, "model": rule_3,
}, },
self.cash_line_1: { self.cash_line_1: {
"model": self.rule_2, "model": self.rule_2,
@ -811,7 +822,6 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
self.rule_1.allow_payment_tolerance = False self.rule_1.allow_payment_tolerance = False
self.rule_1.auto_reconcile = True self.rule_1.auto_reconcile = True
self.rule_1.line_ids = [(5, 0, 0)] self.rule_1.line_ids = [(5, 0, 0)]
self.rule_1.match_text_location_label = False
self._check_statement_matching( self._check_statement_matching(
self.rule_1, self.rule_1,
@ -821,11 +831,17 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
"model": self.rule_1, "model": self.rule_1,
"auto_reconcile": True, "auto_reconcile": True,
}, },
},
)
rule_3 = self.rule_1.copy({"match_text_location_label": False})
self._check_statement_matching(
rule_3,
{
self.bank_line_2: { self.bank_line_2: {
"amls": self.invoice_line_1 "amls": self.invoice_line_1
+ self.invoice_line_2 + self.invoice_line_2
+ self.invoice_line_3, + self.invoice_line_3,
"model": self.rule_1, "model": rule_3,
}, },
}, },
) )
@ -1382,9 +1398,8 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
rule = self._create_reconcile_model( rule = self._create_reconcile_model(
match_partner=False, match_partner=False,
allow_payment_tolerance=False, allow_payment_tolerance=False,
match_text_location_label=False, match_text_location_reference=True,
match_text_location_reference=False, match_text_location_note=True,
match_text_location_note=False,
) )
st_line = self._create_st_line(amount=1000, partner_id=False) st_line = self._create_st_line(amount=1000, partner_id=False)
invoice = self.env["account.move"].create( invoice = self.env["account.move"].create(
@ -1423,8 +1438,10 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
{"amls": term_line, "model": rule}, {"amls": term_line, "model": rule},
) )
# No matching if other checkbox is checked. # No matching if checkbox is unchecked.
rule.match_text_location_note = True rule.match_text_location_label = False
rule.match_text_location_reference = False
rule.match_text_location_note = False
self.assertDictEqual( self.assertDictEqual(
rule._apply_rules(st_line, None), rule._apply_rules(st_line, None),
{}, {},