From 6dc7389be2721421e33c16c16f943c61d46dd50e Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 9 Jul 2009 21:17:18 +0300 Subject: [PATCH] [IMP] Partial restrict operator for domains. In some cases, when the domain is restricted based on an optional field, we want it to match anything if that field is not set. There, use the '=?' operator to match "left = right OR right IS NULL/False". eg. match the production lot among all products, when product is not specified (helps barcode scanners pick up the serial no.). bzr revid: p_christ@hol.gr-20090709181718-dk3ykimzddl9l07o --- bin/osv/expression.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/osv/expression.py b/bin/osv/expression.py index b849e77bd08..7e7f0f4c54c 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -37,7 +37,7 @@ class expression(object): return isinstance(element, (str, unicode)) and element in ['&', '|', '!'] def _is_leaf(self, element, internal=False): - OPS = ('=', '!=', '<>', '<=', '<', '>', '>=', '=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of') + OPS = ('=', '!=', '<>', '<=', '<', '>', '>=', '=?', '=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of') INTERNAL_OPS = OPS + ('inselect',) return (isinstance(element, tuple) or isinstance(element, list)) \ and len(element) == 3 \ @@ -275,6 +275,18 @@ class expression(object): query = '(%s.%s IS NOT NULL and %s.%s != false)' % (table._table, left,table._table, left) elif (((right == False) and (type(right)==bool)) or right is None) and (operator in ['<>', '!=']): query = '%s.%s IS NOT NULL' % (table._table, left) + elif (operator == '=?'): + op = '=' + if (right is False or right is None): + return ( 'TRUE',[]) + if left in table._columns: + format = table._columns[left]._symbol_set[0] + query = '(%s.%s %s %s)' % (table._table, left, op, format) + params = table._columns[left]._symbol_set[1](right) + else: + query = "(%s.%s %s '%%s')" % (table._table, left, op) + params = right + else: if left == 'id': query = '%s.id %s %%s' % (table._table, operator)