changeset a905de74ea98 in modules/product:default
details: https://hg.tryton.org/modules/product?cmd=changeset&node=a905de74ea98
description:
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
diffstat:
product.py | 37 +++++++++++++++++++------------------
1 files changed, 19 insertions(+), 18 deletions(-)
diffs (69 lines):
diff -r 0a248774431a -r a905de74ea98 product.py
--- a/product.py Wed Sep 14 19:27:28 2022 +0200
+++ b/product.py Fri Sep 16 23:37:38 2022 +0200
@@ -20,7 +20,7 @@
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.pool import Pool
from trytond.pyson import Eval, Get, If
-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
@@ -171,19 +171,19 @@
@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,
- ('name',) + tuple(clause[1:]),
- ('code', clause[1], code_value) + tuple(clause[3:]),
- ('products.code', clause[1], code_value) + tuple(clause[3:]),
- ('products.identifiers.code', clause[1], code_value)
- + tuple(clause[3:]),
+ ('name', operator, operand, *extra),
+ ('code', operator, code_value, *extra),
+ ('products.code', operator, code_value, *extra),
+ ('products.identifiers.code', operator, code_value, *extra),
]
@staticmethod
@@ -543,18 +543,19 @@
@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:]),
- ('template.name',) + tuple(clause[1:]),
- ('template.code', clause[1], code_value) + tuple(clause[3:]),
+ ('code', operator, code_value, *extra),
+ ('identifiers.code', operator, code_value, *extra),
+ ('template.name', operator, operand, *extra),
+ ('template.code', operator, code_value, *extra),
]
@staticmethod