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.

94 lines
4.1 KiB

  1. # Copyright 2016 Therp BV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. class TestPartnerRelationCommon(common.TransactionCase):
  5. def setUp(self):
  6. super(TestPartnerRelationCommon, self).setUp()
  7. self.partner_model = self.env['res.partner']
  8. self.category_model = self.env['res.partner.category']
  9. self.type_model = self.env['res.partner.relation.type']
  10. self.selection_model = self.env['res.partner.relation.type.selection']
  11. self.relation_model = self.env['res.partner.relation']
  12. self.relation_all_model = self.env['res.partner.relation.all']
  13. self.partner_01_person = self.partner_model.create({
  14. 'name': 'Test User 1',
  15. 'is_company': False,
  16. 'ref': 'PR01'})
  17. self.partner_02_company = self.partner_model.create({
  18. 'name': 'Test Company',
  19. 'is_company': True,
  20. 'ref': 'PR02'})
  21. # Create partners with specific categories:
  22. self.category_01_ngo = self.category_model.create({'name': 'NGO'})
  23. self.partner_03_ngo = self.partner_model.create({
  24. 'name': 'Test NGO',
  25. 'is_company': True,
  26. 'ref': 'PR03',
  27. 'category_id': [(4, self.category_01_ngo.id)]})
  28. self.category_02_volunteer = self.category_model.create({
  29. 'name': 'Volunteer'})
  30. self.partner_04_volunteer = self.partner_model.create({
  31. 'name': 'Test Volunteer',
  32. 'is_company': False,
  33. 'ref': 'PR04',
  34. 'category_id': [(4, self.category_02_volunteer.id)]})
  35. # Create a new relation type withouth categories:
  36. (self.type_company2person,
  37. self.selection_company2person,
  38. self.selection_person2company) = \
  39. self._create_relation_type_selection({
  40. 'name': 'mixed',
  41. 'name_inverse': 'mixed_inverse',
  42. 'contact_type_left': 'c',
  43. 'contact_type_right': 'p'})
  44. # Create a new relation type with categories:
  45. (self.type_ngo2volunteer,
  46. self.selection_ngo2volunteer,
  47. self.selection_volunteer2ngo) = \
  48. self._create_relation_type_selection({
  49. 'name': 'NGO has volunteer',
  50. 'name_inverse': 'volunteer works for NGO',
  51. 'contact_type_left': 'c',
  52. 'contact_type_right': 'p',
  53. 'partner_category_left': self.category_01_ngo.id,
  54. 'partner_category_right': self.category_02_volunteer.id})
  55. def _create_relation_type_selection(self, vals):
  56. """Create relation type and return this with selection types."""
  57. assert 'name' in vals, (
  58. "Name missing in vals to create relation type. Vals: %s."
  59. % vals)
  60. assert 'name' in vals, (
  61. "Name_inverse missing in vals to create relation type. Vals: %s."
  62. % vals)
  63. new_type = self.type_model.create(vals)
  64. self.assertTrue(
  65. new_type,
  66. msg="No relation type created with vals %s." % vals)
  67. selection_types = self.selection_model.search([
  68. ('type_id', '=', new_type.id)])
  69. for st in selection_types:
  70. if st.is_inverse:
  71. inverse_type_selection = st
  72. else:
  73. type_selection = st
  74. self.assertTrue(
  75. inverse_type_selection,
  76. msg="Failed to find inverse type selection based on"
  77. " relation type created with vals %s." % vals)
  78. self.assertTrue(
  79. type_selection,
  80. msg="Failed to find type selection based on"
  81. " relation type created with vals %s." % vals)
  82. return (new_type, type_selection, inverse_type_selection)
  83. def _create_company2person_relation(self):
  84. """Utility function to get a relation from company 2 partner."""
  85. return self.relation_all_model.create({
  86. 'type_selection_id': self.selection_company2person.id,
  87. 'this_partner_id': self.partner_02_company.id,
  88. 'other_partner_id': self.partner_01_person.id})