From b7b4212971e64ecc60545ba9be1808b91fc0fe25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 8 Jun 2014 00:20:31 +0200 Subject: [PATCH] convert_domain doesn't work with tuple instead of list in domain Use a cleaner algorithm to parse the domain without testing the type. issue3950 review5341003 --- product.py | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/product.py b/product.py index 81291b3806..9e981a0545 100644 --- a/product.py +++ b/product.py @@ -225,32 +225,24 @@ class Product(ModelSQL, ModelView): @classmethod def search_domain(cls, domain, active_test=True): + def is_leaf(expression): + return (isinstance(expression, (list, tuple)) + and len(expression) > 2 + and isinstance(expression[1], basestring) + and expression[1] in OPERATORS) # TODO remove OPERATORS test + def convert_domain(domain): 'Replace missing product field by the template one' - if not domain: - return [] - operator = 'AND' - if isinstance(domain[0], basestring): - operator = domain[0] - domain = domain[1:] - result = [operator] - for arg in domain: - if (isinstance(arg, (list, tuple)) - and len(arg) > 2 - and isinstance(arg[1], basestring) - and arg[1] in OPERATORS): - # clause - field = arg[0].split('.', 1)[0] - if not getattr(cls, field, None): - field = 'template.' + arg[0] - result.append((field,) + tuple(arg[1:])) - else: - result.append(arg) - elif isinstance(arg, list): - # sub-domain - result.append(convert_domain(arg)) + if is_leaf(domain): + field = domain[0].split('.', 1)[0] + if not getattr(cls, field, None): + field = 'template.' + domain[0] + return (field,) + tuple(domain[1:]) else: - result.append(arg) - return result + return domain + elif domain in ['OR', 'AND']: + return domain + else: + return [convert_domain(d) for d in domain] return super(Product, cls).search_domain(convert_domain(domain), active_test=active_test)