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
This commit is contained in:
Cédric Krier committed 2022-09-16 23:37:38 +02:00
1 parent 650a3e733e
commit 2b6ec41401
1 file changed
+10 -9
+10 -9
View File
@@ -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):