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.

76 lines
3.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Camptocamp SA
  3. # Copyright 2016 Therp BV
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import fields
  6. from openerp.exceptions import ValidationError
  7. from .test_partner_relation_common import TestPartnerRelationCommon
  8. class TestPartnerSearch(TestPartnerRelationCommon):
  9. def test_search_relation_type(self):
  10. """Test searching on relation type."""
  11. relation = self._create_company2person_relation()
  12. partners = self.partner_model.search([
  13. ('search_relation_type_id', '=', relation.type_selection_id.id)
  14. ])
  15. self.assertTrue(self.partner_02_company in partners)
  16. partners = self.partner_model.search([
  17. ('search_relation_type_id', '!=', relation.type_selection_id.id)
  18. ])
  19. self.assertTrue(self.partner_01_person in partners)
  20. partners = self.partner_model.search([
  21. ('search_relation_type_id', '=', self.type_company2person.name)
  22. ])
  23. self.assertTrue(self.partner_01_person in partners)
  24. self.assertTrue(self.partner_02_company in partners)
  25. partners = self.partner_model.search([
  26. ('search_relation_type_id', '=', 'unknown relation')
  27. ])
  28. self.assertFalse(partners)
  29. # Check error with invalid search operator:
  30. with self.assertRaises(ValidationError):
  31. partners = self.partner_model.search([
  32. ('search_relation_type_id', 'child_of', 'some parent')
  33. ])
  34. def test_search_relation_partner(self):
  35. """Test searching on related partner."""
  36. self._create_company2person_relation()
  37. partners = self.partner_model.search([
  38. ('search_relation_partner_id', '=', self.partner_02_company.id),
  39. ])
  40. self.assertTrue(self.partner_01_person in partners)
  41. def test_search_relation_date(self):
  42. """Test searching on relations valid on a certain date."""
  43. self._create_company2person_relation()
  44. partners = self.partner_model.search([
  45. ('search_relation_date', '=', fields.Date.today()),
  46. ])
  47. self.assertTrue(self.partner_01_person in partners)
  48. self.assertTrue(self.partner_02_company in partners)
  49. def test_search_any_partner(self):
  50. """Test searching for partner left or right."""
  51. self._create_company2person_relation()
  52. both_relations = self.relation_all_model.search([
  53. ('any_partner_id', '=', self.partner_02_company.id),
  54. ])
  55. self.assertEqual(len(both_relations), 2)
  56. def test_search_partner_category(self):
  57. """Test searching for partners related to partners having category."""
  58. relation_ngo_volunteer = self.relation_all_model.create({
  59. 'this_partner_id': self.partner_03_ngo.id,
  60. 'type_selection_id': self.selection_ngo2volunteer.id,
  61. 'other_partner_id': self.partner_04_volunteer.id,
  62. })
  63. self.assertTrue(relation_ngo_volunteer)
  64. partners = self.partner_model.search([
  65. ('search_relation_partner_category_id', '=',
  66. self.category_02_volunteer.id)
  67. ])
  68. self.assertTrue(self.partner_03_ngo in partners)