From da2e99051a57989c592418668ab4614baf142c4e Mon Sep 17 00:00:00 2001 From: "Jay (Open ERP)" Date: Thu, 22 Oct 2009 20:06:41 +0530 Subject: [PATCH] [FIX] Expression : domain calculation failes, max. recursion error protected bzr revid: jvo@tinyerp.com-20091022143641-l5b4jbk0spce8b1t --- bin/osv/expression.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bin/osv/expression.py b/bin/osv/expression.py index 3b4516e6657..d695fc62230 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -46,18 +46,25 @@ class expression(object): def __execute_recursive_in(self, cr, s, f, w, ids, op, type): res = [] - if not ids: - return [] - if op not in ('<','>','=','>=','<=','not in'): - op = 'in' - for i in range(0, len(ids), cr.IN_MAX): - subids = ids[i:i+cr.IN_MAX] - cr.execute('SELECT "%s"' \ - ' FROM "%s"' \ - ' WHERE "%s" %s (%s)' % (s, f, w, op, ','.join(['%s']*len(subids))), - subids) - res += [r[0] for r in cr.fetchall() if r[0]] - return res + (res and self.__execute_recursive_in(cr, s, f, w, res, op, type) or []) + if ids: + if op in ['<','>','>=','<=']: + cr.execute('SELECT "%s"' \ + ' FROM "%s"' \ + ' WHERE "%s" %s %s' % (s, f, w, op, ids[0])) + res.extend([r[0] for r in cr.fetchall()]) + else: + for i in range(0, len(ids), cr.IN_MAX): + subids = ids[i:i+cr.IN_MAX] + cr.execute('SELECT "%s"' \ + ' FROM "%s"' \ + ' WHERE "%s" in (%s)' % (s, f, w, ','.join(['%s']*len(subids))), + subids) + res.extend([r[0] for r in cr.fetchall()]) + else: + cr.execute('SELECT distinct("%s")' \ + ' FROM "%s" where "%s" is not null' % (s, f, s)), + res.extend([r[0] for r in cr.fetchall()]) + return res def __init__(self, exp): # check if the expression is valid