From f0559e37fb25ccd98281d796bf3118e2518e047c 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 --- account.py | 16 +++++++++------- journal.py | 16 +++++++++------- tax.py | 15 ++++++++------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/account.py b/account.py index 3c83a76fb3..de285c3f5d 100644 --- a/account.py +++ b/account.py @@ -21,7 +21,8 @@ from trytond.modules.currency.fields import Monetary from trytond.pool import Pool from trytond.pyson import Bool, Eval, If, PYSONEncoder from trytond.report import Report -from trytond.tools import grouped_slice, lstrip_wildcard, reduce_ids +from trytond.tools import ( + grouped_slice, is_full_text, lstrip_wildcard, reduce_ids) from trytond.transaction import Transaction from trytond.wizard import ( Button, StateAction, StateTransition, StateView, Wizard) @@ -619,16 +620,17 @@ def AccountMixin(template=False): @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:]), - (cls._rec_name,) + tuple(clause[1:]), + ('code', operator, code_value, *extra), + (cls._rec_name, operator, operand, *extra), ] @staticmethod diff --git a/journal.py b/journal.py index 5af1c96d98..6f8e393486 100644 --- a/journal.py +++ b/journal.py @@ -14,7 +14,8 @@ from trytond.modules.company.model import ( from trytond.modules.currency.fields import Monetary from trytond.pool import Pool from trytond.pyson import Bool, Eval, Id -from trytond.tools import grouped_slice, lstrip_wildcard, reduce_ids +from trytond.tools import ( + grouped_slice, is_full_text, lstrip_wildcard, reduce_ids) from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction @@ -74,16 +75,17 @@ class Journal( @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:]), - (cls._rec_name,) + tuple(clause[1:]), + ('code', operator, code_value, *extra), + (cls._rec_name, operator, operand, *extra), ] @classmethod diff --git a/tax.py b/tax.py index ef62a59f6f..9c0b5b66ed 100644 --- a/tax.py +++ b/tax.py @@ -18,7 +18,7 @@ from trytond.model.exceptions import AccessError from trytond.modules.currency.fields import Monetary from trytond.pool import Pool from trytond.pyson import Bool, Eval, If, PYSONEncoder -from trytond.tools import cursor_dict, lstrip_wildcard +from trytond.tools import cursor_dict, is_full_text, lstrip_wildcard from trytond.transaction import Transaction from trytond.wizard import Button, StateAction, StateView, Wizard @@ -220,16 +220,17 @@ class TaxCode( @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:]), - (cls._rec_name,) + tuple(clause[1:]), + ('code', operator, code_value, *extra), + (cls._rec_name, operator, operand, *extra), ] @classmethod