From 2b6ec41401cf1590b192e5bd9588dff1d30b362c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 16 Sep 2022 23:37:38 +0200 Subject: [PATCH] Left strip code operand only when it is a full text This allow to write query with double wildcard to force a full text search on the code. issue11682 review443571003 --- party.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/party.py b/party.py index 3d27a0a0ad..55d9039a05 100644 --- a/party.py +++ b/party.py @@ -14,7 +14,7 @@ from trytond.model import ( from trytond.model.exceptions import AccessError from trytond.pool import Pool from trytond.pyson import Bool, Eval -from trytond.tools import lstrip_wildcard +from trytond.tools import is_full_text, lstrip_wildcard from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction from trytond.wizard import Button, StateTransition, StateView, Wizard @@ -295,18 +295,19 @@ class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin): @classmethod def search_rec_name(cls, name, clause): - if clause[1].startswith('!') or clause[1].startswith('not '): + _, operator, operand, *extra = clause + if operator.startswith('!') or operator.startswith('not '): bool_op = 'AND' else: bool_op = 'OR' - code_value = clause[2] - if clause[1].endswith('like'): - code_value = lstrip_wildcard(clause[2]) + code_value = operand + if operator.endswith('like') and is_full_text(operand): + code_value = lstrip_wildcard(operand) return [bool_op, - ('code', clause[1], code_value) + tuple(clause[3:]), - ('identifiers.code', clause[1], code_value) + tuple(clause[3:]), - ('name',) + tuple(clause[1:]), - ('contact_mechanisms.rec_name',) + tuple(clause[1:]), + ('code', operator, code_value, *extra), + ('identifiers.code', operator, code_value, *extra), + ('name', operator, operand, *extra), + ('contact_mechanisms.rec_name', operator, operand, *extra), ] def address_get(self, type=None):