[FIX]:exception handling in netrpc
[odoo/odoo.git] / openerp / osv / expression.py
index cb8cfea..c81ee89 100644 (file)
@@ -69,7 +69,7 @@ and you would be tempted to believe something like this would be possible:
   ['!', ['=', 'company_id.name', ['&', ..., ...]]]
 
 That is, a domain could be a valid operand. But this is not the case. A domain
-is really limited to a two-level nature, and can not takes a recursive form: a
+is really limited to a two-level nature, and can not take a recursive form: a
 domain is not a valid second-level operand.
 
 Unaccent - Accent-insensitive search
@@ -77,11 +77,11 @@ Unaccent - Accent-insensitive search
 OpenERP will use the SQL function 'unaccent' when available for the 'ilike' and
 'not ilike' operators, and enabled in the configuration.
 Normally the 'unaccent' function is obtained from the PostgreSQL 'unaccent'
-contrib module[0]. 
+contrib module[0].
 
 
 ..todo: The following explanation should be moved in some external installation
-        guide 
+        guide
 
 The steps to install the module might differ on specific PostgreSQL versions.
 We give here some instruction for PostgreSQL 9.x on a Ubuntu system.
@@ -191,12 +191,12 @@ def combine(operator, unit, zero, domains):
 
        :param unit: the identity element of the domains "set" with regard to the operation
                     performed by ``operator``, i.e the domain component ``i`` which, when
-                    combined with any domain ``x`` via ``operator``, yields ``x``. 
+                    combined with any domain ``x`` via ``operator``, yields ``x``.
                     E.g. [(1,'=',1)] is the typical unit for AND_OPERATOR: adding it
                     to any domain component gives the same domain.
        :param zero: the absorbing element of the domains "set" with regard to the operation
                     performed by ``operator``, i.e the domain component ``z`` which, when
-                    combined with any domain ``x`` via ``operator``, yields ``z``. 
+                    combined with any domain ``x`` via ``operator``, yields ``z``.
                     E.g. [(1,'=',1)] is the typical zero for OR_OPERATOR: as soon as
                     you see it in a domain component the resulting domain is the zero.
        :param domains: a list of normalized domains.
@@ -462,7 +462,7 @@ class expression(object):
                 # 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, [(field_path[1], operator, right)], context=context)
-                    right1 = table.search(cr, uid, [(field_path[0], 'in', right)], context=context)
+                    right1 = table.search(cr, uid, [(field_path[0],'in', right)], context=dict(context, active_test=False))
                     self.__exp[i] = ('id', 'in', right1)
 
                 if not isinstance(field, fields.property):
@@ -593,23 +593,13 @@ class expression(object):
                         if operator in NEGATIVE_TERM_OPERATORS:
                             res_ids.append(False) # TODO this should not be appended if False was in 'right'
                         return (left, 'in', res_ids)
-
-                    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
-                        if m2o_str:
-                            self.__exp[i] = _get_expression(field_obj, cr, uid, left, right, operator, context=context)
-                    elif right == []:
-                        pass # Handled by __leaf_to_sql().
-                    else: # right is False
-                        pass # Handled by __leaf_to_sql().
+                    # resolve string-based m2o criterion into IDs
+                    if isinstance(right, basestring) or \
+                            right and isinstance(right, (tuple,list)) and all(isinstance(item, basestring) for item in right):
+                        self.__exp[i] = _get_expression(field_obj, cr, uid, left, right, operator, context=context)
+                    else: 
+                        # right == [] or right == False and all other cases are handled by __leaf_to_sql()
+                        pass
 
             else:
                 # other field type