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.

136 lines
5.0 KiB

  1. # Copyright 2018 David Juaneda - <djuaneda@sdi.es>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests.common import TransactionCase
  4. class TestMailActivityBoardMethods(TransactionCase):
  5. def setUp(self):
  6. super(TestMailActivityBoardMethods, self).setUp()
  7. # Set up activities
  8. # Create a user as 'Crm Salesman' and added few groups
  9. self.employee = self.env['res.users'].create({
  10. 'company_id': self.env.ref("base.main_company").id,
  11. 'name': "Employee",
  12. 'login': "csu",
  13. 'email': "crmuser@yourcompany.com",
  14. 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])]
  15. })
  16. # lead_model_id = self.env['ir.model']._get('crm.lead').id
  17. partner_model_id = self.env['ir.model']._get('res.partner').id
  18. ActivityType = self.env['mail.activity.type']
  19. self.activity1 = ActivityType.create({
  20. 'name': 'Initial Contact',
  21. 'days': 5,
  22. 'summary': 'ACT 1 : Presentation, barbecue, ... ',
  23. 'res_model_id': partner_model_id,
  24. })
  25. self.activity2 = ActivityType.create({
  26. 'name': 'Call for Demo',
  27. 'days': 6,
  28. 'summary': 'ACT 2 : I want to show you my ERP !',
  29. 'res_model_id': partner_model_id,
  30. })
  31. self.activity3 = ActivityType.create({
  32. 'name': 'Celebrate the sale',
  33. 'days': 3,
  34. 'summary': 'ACT 3 : '
  35. 'Beers for everyone because I am a good salesman !',
  36. 'res_model_id': partner_model_id,
  37. })
  38. # I create an opportunity, as employee
  39. self.partner_client = self.env.ref("base.res_partner_1")
  40. self.act1 = self.env['mail.activity'].sudo().create({
  41. 'activity_type_id': self.activity3.id,
  42. 'note': 'Partner activity 1.',
  43. 'res_id': self.partner_client.id,
  44. 'res_model_id': partner_model_id,
  45. 'user_id': self.employee.id
  46. })
  47. self.act2 = self.env['mail.activity'].sudo().create({
  48. 'activity_type_id': self.activity2.id,
  49. 'note': 'Partner activity 2.',
  50. 'res_id': self.partner_client.id,
  51. 'res_model_id': partner_model_id,
  52. 'user_id': self.employee.id
  53. })
  54. self.act3 = self.env['mail.activity'].sudo().create({
  55. 'activity_type_id': self.activity3.id,
  56. 'note': 'Partner activity 3.',
  57. 'res_id': self.partner_client.id,
  58. 'res_model_id': partner_model_id,
  59. 'user_id': self.employee.id
  60. })
  61. def get_view(self, activity):
  62. action = activity.open_origin()
  63. result = self.env[action.get('res_model')]\
  64. .load_views(action.get('views'))
  65. return result.get('fields_views').get(action.get('view_mode'))
  66. def test_open_origin_res_partner(self):
  67. """ This test case checks
  68. - If the method redirects to the form view of the correct one
  69. of an object of the 'res.partner' class to which the activity
  70. belongs.
  71. """
  72. # Id of the form view for the class 'crm.lead', type 'lead'
  73. form_view_partner_id = self.env.ref('base.view_partner_form').id
  74. # Id of the form view return open_origin()
  75. view = self.get_view(self.act1)
  76. # Check the next view is correct
  77. self.assertEqual(form_view_partner_id, view.get('view_id'))
  78. # Id of the form view return open_origin()
  79. view = self.get_view(self.act2)
  80. # Check the next view is correct
  81. self.assertEqual(form_view_partner_id, view.get('view_id'))
  82. # Id of the form view return open_origin()
  83. view = self.get_view(self.act3)
  84. # Check the next view is correct
  85. self.assertEqual(form_view_partner_id, view.get('view_id'))
  86. def test_redirect_to_activities(self):
  87. """ This test case checks
  88. - if the method returns the correct action,
  89. - if the correct activities are shown.
  90. """
  91. action_id = self.env.ref(
  92. 'mail_activity_board.open_boards_activities').id
  93. action = self.partner_client\
  94. .redirect_to_activities(**{'id': self.partner_client.id})
  95. self.assertEqual(action.get('id'), action_id)
  96. kwargs = {
  97. 'groupby': [
  98. "activity_type_id"
  99. ]
  100. }
  101. kwargs['domain'] = action.get('domain')
  102. result = self.env[action.get('res_model')]\
  103. .load_views(action.get('views'))
  104. fields = result.get('fields_views').get('kanban').get('fields')
  105. kwargs['fields'] = list(fields.keys())
  106. result = self.env['mail.activity'].read_group(**kwargs)
  107. acts = []
  108. for group in result:
  109. records = self.env['mail.activity'].search_read(
  110. domain=group.get('__domain'), fields=kwargs['fields']
  111. )
  112. acts += [id.get('id') for id in records]
  113. for act in acts:
  114. self.assertIn(act, self.partner_client.activity_ids.ids)