From 7e5d7e7b33df00b6febf68333d4c27a81c789003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 31 Mar 2025 08:49:42 +0200 Subject: [PATCH] [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 https://github.com/odoo/odoo/commit/ee22c02b1f0348e9dcedab1280de9ec8db8fae0c --- .../models/account_reconcile_model.py | 2 +- .../tests/test_reconciliation_match.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/account_reconcile_model_oca/models/account_reconcile_model.py b/account_reconcile_model_oca/models/account_reconcile_model.py index 766e5923..53eb028e 100644 --- a/account_reconcile_model_oca/models/account_reconcile_model.py +++ b/account_reconcile_model_oca/models/account_reconcile_model.py @@ -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 diff --git a/account_reconcile_model_oca/tests/test_reconciliation_match.py b/account_reconcile_model_oca/tests/test_reconciliation_match.py index bb46c290..8ee89599 100644 --- a/account_reconcile_model_oca/tests/test_reconciliation_match.py +++ b/account_reconcile_model_oca/tests/test_reconciliation_match.py @@ -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"),