+ def _get_expression(field_obj,cr, uid, left, right, operator, context=None):
+ if context is None:
+ context = {}
+ c = context.copy()
+ c['active_test'] = False
+ #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)
+ else:
+ right = map(lambda x: x[0], res_ids)
+ return (left, 'in', right)
+
+ m2o_str = False
+ 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
+ elif right == []:
+ m2o_str = False
+ if operator in ('not in', '!=', '<>'):
+ # (many2one not in []) should return all records
+ self.__exp[i] = self.__DUMMY_LEAF
+ else:
+ self.__exp[i] = ('id','=',0)
+ 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)