diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index 3843d374e64..e2a104bfff2 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -396,7 +396,7 @@ assert res_8 == [1] assert res_9 == [] - # get the companies referenced by some currency (this is normally the main company) + # get the companies referenced by some currency (this is normally the main company) using a weird negative domain res_10 = self.search(cr, uid, [('currency_ids', 'not like', 'probably_unexisting_name')]) res_11 = self.search(cr, uid, [('currency_ids', 'not in', [max_currency_id + 1])]) res_12 = self.search(cr, uid, [('currency_ids', '!=', False)]) @@ -408,6 +408,20 @@ assert res_10 == res_11 assert res_10 == res_12 assert res_10 == res_13 + + # try testing real subsets with IN/NOT IN + res_partner = self.pool.get('res.partner') + res_users = self.pool.get('res.users') + p1, _ = res_partner.name_create(cr, uid, "Dédé Boitaclou") + p2, _ = res_partner.name_create(cr, uid, "Raoulette Pizza O'poil") + u1a = res_users.create(cr, uid, {'login': 'dbo', 'partner_id': p1}) + u1b = res_users.create(cr, uid, {'login': 'dbo2', 'partner_id': p1}) + u2 = res_users.create(cr, uid, {'login': 'rpo', 'partner_id': p2}) + assert [p1] == res_partner.search(cr, uid, [('user_ids', 'in', u1a)]), "o2m IN accept single int on right side" + assert [p1,p2] == res_partner.search(cr, uid, [('user_ids', 'in', [u1a,u2])]), "o2m IN matches any on the right side" + all_partners = res_partner.search(cr, uid, []) + assert (set(all_partners) - set([p1])) == set(res_partner.search(cr, uid, [('user_ids', 'not in', u1a)])), "o2m NOT IN matches none on the right side" + assert (set(all_partners) - set([p1,p2])) == set(res_partner.search(cr, uid, [('user_ids', 'not in', [u1b, u2])])), "o2m NOT IN matches none on the right side" # child_of x returns x and its children (direct or not). company = self.browse(cr, uid, ref('ymltest_company3')) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 5f2c0b915c1..2b2d33a496e 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -540,7 +540,8 @@ class expression(object): ids2 = select_from_where(cr, field._fields_id, field_obj._table, 'id', ids2, operator) if ids2: call_null = False - self.__exp[i] = ('id', 'in', ids2) + o2m_op = 'not in' if operator in NEGATIVE_TERM_OPERATORS else 'in' + self.__exp[i] = ('id', o2m_op, ids2) if call_null: o2m_op = 'in' if operator in NEGATIVE_TERM_OPERATORS else 'not in'