From 55b7b1f0124fa7a8b02fd4ec7438f2e5d169920d Mon Sep 17 00:00:00 2001 From: "Anup,Jay" <> Date: Wed, 6 Oct 2010 23:22:41 +0530 Subject: [PATCH] [FIX] Expression : Corrected operator handling for domains containing Many2one fields lp bug: https://launchpad.net/bugs/651999 fixed bzr revid: jvo@tinyerp.com-20101006175241-1iefvnvthxoi49qr --- bin/osv/expression.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bin/osv/expression.py b/bin/osv/expression.py index d2f1f29..a49a14b 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -285,12 +285,16 @@ class expression(object): context = {} c = context.copy() c['active_test'] = False - dict_op = {'not in':'!=','in':'='} + #Special treatment to ill-formed domains + operator = ( operator in ['<','>','<=','>='] ) and 'in' or operator + + dict_op = {'not in':'!=','in':'=','=':'in','!=':'not in','<>':'not in'} if isinstance(right,tuple): right = list(right) if (not isinstance(right,list)) and operator in ['not in','in']: operator = dict_op[operator] - + elif isinstance(right,list) and operator in ['<>','!=','=']: #for domain (FIELD,'=',['value1','value2']) + operator = dict_op[operator] res_ids = field_obj.name_search(cr, uid, right, [], operator, limit=None, context=c) if not res_ids: return ('id','=',0) @@ -299,14 +303,21 @@ class expression(object): return (left, 'in', right) m2o_str = False - if isinstance(right, basestring): # and not isinstance(field, fields.related): - m2o_str = True - elif isinstance(right, list) or isinstance(right, tuple): - m2o_str = True - for ele in right: - if not isinstance(ele, basestring): - m2o_str = False - break + if right: + if isinstance(right, basestring): # and not isinstance(field, fields.related): + m2o_str = True + elif isinstance(right,(list,tuple)): + m2o_str = True + for ele in right: + if not isinstance(ele, basestring): + m2o_str = False + break + else: + new_op = '=' + if operator in ['not like','not ilike','not in','<>','!=']: + new_op = '!=' + #Is it ok to put 'left' and not 'id' ? + self.__exp[i] = (left,new_op,False) if m2o_str: self.__exp[i] = _get_expression(field_obj,cr, uid, left, right, operator, context=context) -- 1.7.10.4