diff --git a/bin/osv/expression.py b/bin/osv/expression.py index 3281fd29f7c..cbb6a0f985b 100644 --- a/bin/osv/expression.py +++ b/bin/osv/expression.py @@ -143,12 +143,18 @@ class expression(object): if len(fargs) > 1: if field._type == 'many2one': right = field_obj.search(cr, uid, [(fargs[1], operator, right)], context=context) - self.__exp[i] = (fargs[0], 'in', right) + if right == []: + self.__exp[i] = ( 'id', '=', 0 ) + else: + self.__exp[i] = (fargs[0], 'in', right) # Making search easier when there is a left operand as field.o2m or field.m2m if field._type in ['many2many','one2many']: right = field_obj.search(cr, uid, [(fargs[1], operator, right)], context=context) right1 = table.search(cr, uid, [(fargs[0],'in', right)], context=context) - self.__exp[i] = ('id', 'in', right1) + if right1 == []: + self.__exp[i] = ( 'id', '=', 0 ) + else: + self.__exp[i] = ('id', 'in', right1) if not isinstance(field,fields.property): continue @@ -313,6 +319,13 @@ class expression(object): 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','<>','!=']: