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:
+19
-18
@@ -20,7 +20,7 @@ from trytond.modules.company.model import (
|
||||
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 @@ class Template(
|
||||
|
||||
@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 @@ class Product(
|
||||
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user