From 9be9407f3ccb81dc85e9f424cca2332a7a95cd9a Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Tue, 28 Feb 2023 10:43:45 +0000 Subject: [PATCH] [FIX] account: fix search on account for "=" and "!=" operators Steps to reproduce: - Create 2 accounts: 1) * Code: 1000 * Account Name: Test 2) * Code 1000A * Account Name: TestA - Create a journal item for each account - Go to Accounting / Accounting / Journal Items (list view) - Add custom filter: ("Account", "is equal to", "1000 Test") Journal items from both the created accounts are retrieved. As a strict equal is requested, it shouldn't find the journal item linked to account "1000A TestA". Cause: When searching on an account, the first part of the search is used to find a code that begins with that part (ilike operation), regardless of the actual operator (i.e. "=" in this case). It has been done that way because we suppose that most of the times customer is starting his search with the beginning of the code of the account he is searching, which is not incorrect. But the case of the "=" operator has not been handled. opw-3179681 closes odoo/odoo#114927 X-original-commit: dfd9bee8c07b927a97823eb8ede7dc2b2a4c435a Signed-off-by: Olivier Colson (oco) Signed-off-by: Anh Thao PHAM --- addons/account/models/account_account.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 90b15d02a25..32d13df16ca 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -566,7 +566,10 @@ class AccountAccount(models.Model): self.env.company.id, self._context.get('partner_id'), self._context.get('move_type')) domain = domain or [] if name: - name_domain = ['|', ('code', '=ilike', name.split(' ')[0] + '%'), ('name', operator, name)] + if operator in ('=', '!='): + name_domain = ['|', ('code', '=', name.split(' ')[0]), ('name', operator, name)] + else: + name_domain = ['|', ('code', '=ilike', name.split(' ')[0] + '%'), ('name', operator, name)] if operator in expression.NEGATIVE_TERM_OPERATORS: name_domain = ['&', '!'] + name_domain[1:] domain = expression.AND([name_domain, domain])