Escape wildcard in tree separator for name domain

issue11321
review356281002
This commit is contained in:
Cédric Krier committed 2022-04-16 11:25:38 +02:00
1 parent 86534e2116
commit 38efaaf887
3 files changed
+20 -1

No files matched your search

+3 -1
View File
@@ -3,6 +3,7 @@
from itertools import chain
from trytond.i18n import gettext
from trytond.tools import escape_wildcard
from .modelstorage import ValidationError
@@ -22,7 +23,8 @@ def tree(parent='parent', name='name', separator=None):
def __setup__(cls):
super(TreeMixin, cls).__setup__()
field = getattr(cls, name)
clause = (name, 'not like', '%' + separator + '%')
clause = (
name, 'not like', '%' + escape_wildcard(separator) + '%')
# If TreeMixin is after the class where name is defined in
# __mro__, it modifies the base field copied so it must ensure
# to add only once the domain
+9
View File
@@ -188,6 +188,15 @@ class TreeMixinTestCase(unittest.TestCase):
with self.assertRaises(DomainValidationError):
record.save()
@with_transaction()
def test_name_domain_wildcard(self):
"Test name domain on tree with wildcard"
pool = Pool()
Tree = pool.get('test.tree_wildcard')
record = Tree(name="test 10%")
record.save()
@with_transaction()
def test_rec_name(self):
"Test rec_name"
+8
View File
@@ -12,6 +12,13 @@ class Tree(tree(separator=' / '), ModelSQL):
parent = fields.Many2One('test.tree', "Parent")
class TreeWildcard(tree(separator='\\'), ModelSQL):
"Tree separator wildcard"
__name__ = 'test.tree_wildcard'
name = fields.Char("Name")
parent = fields.Many2One('test.tree_wildcard', "Parent")
class Polytree(tree(parent='parents'), ModelSQL):
"PolyTree"
__name__ = 'test.polytree'
@@ -30,6 +37,7 @@ class PolytreeEdge(ModelSQL):
def register(module):
Pool.register(
Tree,
TreeWildcard,
Polytree,
PolytreeEdge,
module=module, type_='model')