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.

81 lines
3.3 KiB

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