You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Guewen Baconnier
  5. # Copyright 2015 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #
  21. import openerp.tests.common as common
  22. class TestActiveSearch(common.TransactionCase):
  23. def test_model_with_active_field(self):
  24. cr, uid = self.cr, self.uid
  25. IrModel = self.registry('ir.model')
  26. partner_model_id = IrModel.search(cr, uid,
  27. [('model', '=', 'res.partner')],
  28. limit=1)[0]
  29. partner_model = IrModel.browse(cr, uid, partner_model_id)
  30. self.assertTrue(partner_model.has_an_active_field)
  31. self.assertIn(partner_model_id,
  32. IrModel.search(cr, uid,
  33. [('has_an_active_field', '=', True)]))
  34. self.assertIn(partner_model_id,
  35. IrModel.search(cr, uid,
  36. [('has_an_active_field', '!=', False)]))
  37. def test_model_without_active_field(self):
  38. cr, uid = self.cr, self.uid
  39. IrModel = self.registry('ir.model')
  40. country_model_id = IrModel.search(cr, uid,
  41. [('model', '=', 'res.country')],
  42. limit=1)
  43. country_model = IrModel.browse(cr, uid, country_model_id[0])
  44. self.assertFalse(country_model.has_an_active_field)
  45. self.assertNotIn(country_model_id,
  46. IrModel.search(cr, uid,
  47. [('has_an_active_field', '=', False)]))
  48. self.assertNotIn(country_model_id,
  49. IrModel.search(cr, uid,
  50. [('has_an_active_field', '!=', True)]))