[FIX] account_reconcile_model_oca: bank rec match with empty name

It can be that the name field on the account_move_line is an empty
string (as opposed to NULL). This can happen, for instance, when
generating the payment term line for Switzerland without the appropriate
fields on the company.

Since there are instances when the payment term's name is an empty
string, we can retrieve these lines and automatically match them with
payments from  the bank reconciliation model. This can happen
automatically, with exact matches between a payment with a near-empty
reference (when the payment ref is just "/" or "?", this is sanitized
and ends up as an empty string for the purposes of comparison), and
these empty string payment term invoice lines.

The query that fetches the candidate lines for exact matches already
excludes those lines with a NULL move_line name, move ref, move name.
The natural extension of this behav

Related to ee22c02b1f
pull/816/head
Víctor Martínez 2025-03-31 08:49:42 +02:00
parent 35908dcdbf
commit 7e5d7e7b33
2 changed files with 14 additions and 1 deletions

View File

@ -445,7 +445,7 @@ class AccountReconcileModel(models.Model):
FROM {tables}
JOIN account_move account_move_line__move_id
ON account_move_line__move_id.id = account_move_line.move_id
WHERE {where_clause} AND {table_alias}.{field} IS NOT NULL
WHERE {where_clause} AND COALESCE({table_alias}.{field}, '') != ''
"""
)
all_params += where_params

View File

@ -1439,6 +1439,19 @@ class TestReconciliationMatchingRules(AccountTestInvoicingCommon):
{},
)
with self.subTest(
rule_field="match_text_location_label", st_line_field="payment_ref"
):
with rollback():
term_line.name = ""
st_line.payment_ref = "/?"
# No exact matching when the term line name is an empty string
self.assertDictEqual(
rule._apply_rules(st_line, None),
{},
)
for rule_field, st_line_field in (
("match_text_location_label", "payment_ref"),
("match_text_location_reference", "ref"),