changeset a760d1b53d3d in trytond:6.2 details: https://hg.tryton.org/trytond?cmd=changeset&node=a760d1b53d3d description: Escape wildcard in tree separator for name domain
issue11321 review356281002 (grafted from 8b1644ea12fad5b20ebd52a6641bd09570e0631c) diffstat: trytond/model/tree.py | 5 ++++- trytond/tests/test_tree.py | 9 +++++++++ trytond/tests/tree.py | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletions(-) diffs (66 lines): diff -r a610674ec95c -r a760d1b53d3d trytond/model/tree.py --- a/trytond/model/tree.py Fri Apr 22 18:32:25 2022 +0200 +++ b/trytond/model/tree.py Sat Apr 16 11:25:38 2022 +0200 @@ -3,6 +3,8 @@ from itertools import chain from trytond.i18n import gettext +from trytond.tools import escape_wildcard + from .modelstorage import ValidationError @@ -19,7 +21,8 @@ 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 diff -r a610674ec95c -r a760d1b53d3d trytond/tests/test_tree.py --- a/trytond/tests/test_tree.py Fri Apr 22 18:32:25 2022 +0200 +++ b/trytond/tests/test_tree.py Sat Apr 16 11:25:38 2022 +0200 @@ -189,6 +189,15 @@ 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" pool = Pool() diff -r a610674ec95c -r a760d1b53d3d trytond/tests/tree.py --- a/trytond/tests/tree.py Fri Apr 22 18:32:25 2022 +0200 +++ b/trytond/tests/tree.py Sat Apr 16 11:25:38 2022 +0200 @@ -12,6 +12,13 @@ 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 @@ def register(module): Pool.register( Tree, + TreeWildcard, Polytree, PolytreeEdge, module=module, type_='model')