diff --git a/addons/account/tests/test_search.py b/addons/account/tests/test_search.py index 0e93da0c0bc..6f4a56cf8e6 100644 --- a/addons/account/tests/test_search.py +++ b/addons/account/tests/test_search.py @@ -12,6 +12,8 @@ class TestSearch(TransactionCase): cr, uid = self.cr, self.uid self.account_model = self.registry('account.account') self.account_type_model = self.registry('account.account.type') + self.res_partner_model = self.registry('res.partner') + self.account_payment_term_model = self.registry('account.payment.term') ac_ids = self.account_type_model.search(cr, uid, [], limit=1) self.atax = (int(self.account_model.create(cr, uid, dict( name="Tax Received", @@ -33,6 +35,9 @@ class TestSearch(TransactionCase): self.all_ids = [self.atax[0], self.apurchase[0], self.asale[0]] + self.a_partner = self.res_partner_model.create(cr, uid, {'name':'test partner'}) + self.a_payment_term = self.account_payment_term_model.create(cr, uid, {'name':'test payment term'}) + def test_name_search(self): cr, uid = self.cr, self.uid atax_ids = self.account_model.name_search(cr, uid, name="Tax", operator='ilike', args=[('id', 'in', self.all_ids)]) @@ -58,3 +63,13 @@ class TestSearch(TransactionCase): asale_ids = self.account_model.name_search(cr, uid, name='Product Sales', operator='not ilike', args=[('id', 'in', self.all_ids)]) self.assertEqual(set([self.atax[0], self.apurchase[0]]), set([a[0] for a in asale_ids]), "name_search 'not ilike Product Sales' should have returned all but Product Sales account") + + def test_property_unset_search(self): + cr, uid = self.cr, self.uid + + partner_ids = self.res_partner_model.search(cr, uid, [('property_payment_term', '=', False), ('id', '=', self.a_partner)]) + self.assertTrue(partner_ids, "unset property field 'propety_payment_term' should have been found") + + self.res_partner_model.write(cr, uid, [self.a_partner], {'property_payment_term': self.a_payment_term}) + partner_ids = self.res_partner_model.search(cr, uid, [('property_payment_term', '=', False), ('id', '=', self.a_partner)]) + self.assertFalse(partner_ids, "set property field 'propety_payment_term' should not have been found") diff --git a/openerp/addons/base/res/ir_property.py b/openerp/addons/base/res/ir_property.py index 859f97330d4..f14c68d06d3 100644 --- a/openerp/addons/base/res/ir_property.py +++ b/openerp/addons/base/res/ir_property.py @@ -259,12 +259,19 @@ class ir_property(osv.osv): @api.model def search_multi(self, name, model, operator, value): """ Return a domain for the records that match the given condition. """ + default_matches = False + field = self.env[model]._fields[name] if field.type == 'many2one': comodel = field.comodel_name def makeref(value): return value and '%s,%s' % (comodel, value) - if operator in ('=', '!=', '<=', '<', '>', '>='): + if operator == "=": + value = makeref(value) + # if searching properties not set, search those not in those set + if value is False: + default_matches = True + elif operator in ('!=', '<=', '<', '>', '>='): value = makeref(value) elif operator in ('in', 'not in'): value = map(makeref, value) @@ -283,7 +290,6 @@ class ir_property(osv.osv): # retrieve the records corresponding to the properties that match good_ids = [] - default_matches = False for prop in props: if prop.res_id: res_model, res_id = prop.res_id.split(',')