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.

118 lines
4.7 KiB

6 years ago
6 years ago
  1. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests.common import TransactionCase
  4. from odoo.exceptions import ValidationError
  5. class TestMailActivityTeam(TransactionCase):
  6. def setUp(self):
  7. super(TestMailActivityTeam, self).setUp()
  8. self.env["mail.activity.team"].search([]).unlink()
  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, [
  15. self.env.ref('base.group_user').id,
  16. self.env.ref('base.group_partner_manager').id])]
  17. })
  18. self.employee2 = self.env['res.users'].create({
  19. 'company_id': self.env.ref("base.main_company").id,
  20. 'name': "Employee 2",
  21. 'login': "csu2",
  22. 'email': "crmuser2@yourcompany.com",
  23. 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])]
  24. })
  25. self.partner_ir_model = self.env['ir.model']._get('res.partner')
  26. activity_type_model = self.env['mail.activity.type']
  27. self.activity1 = activity_type_model.create({
  28. 'name': 'Initial Contact',
  29. 'days': 5,
  30. 'summary': 'ACT 1 : Presentation, barbecue, ... ',
  31. 'res_model_id': self.partner_ir_model.id,
  32. })
  33. self.activity2 = activity_type_model.create({
  34. 'name': 'Call for Demo',
  35. 'days': 6,
  36. 'summary': 'ACT 2 : I want to show you my ERP !',
  37. 'res_model_id': self.partner_ir_model.id,
  38. })
  39. self.partner_client = self.env.ref("base.res_partner_1")
  40. self.act1 = self.env['mail.activity'].sudo(self.employee).create({
  41. 'activity_type_id': self.activity1.id,
  42. 'note': 'Partner activity 1.',
  43. 'res_id': self.partner_client.id,
  44. 'res_model_id': self.partner_ir_model.id,
  45. 'user_id': self.employee.id,
  46. })
  47. self.team1 = self.env['mail.activity.team'].sudo().create({
  48. 'name': 'Team 1',
  49. 'res_model_ids': [(6, 0, [self.partner_ir_model.id])],
  50. 'member_ids': [(6, 0, [self.employee.id])],
  51. })
  52. self.team2 = self.env['mail.activity.team'].sudo().create({
  53. 'name': 'Team 2',
  54. 'res_model_ids': [(6, 0, [self.partner_ir_model.id])],
  55. 'member_ids': [(6, 0, [self.employee.id, self.employee2.id])],
  56. })
  57. self.act2 = self.env['mail.activity'].sudo(self.employee).create({
  58. 'activity_type_id': self.activity2.id,
  59. 'note': 'Partner activity 2.',
  60. 'res_id': self.partner_client.id,
  61. 'res_model_id': self.partner_ir_model.id,
  62. 'user_id': self.employee.id,
  63. })
  64. def test_missing_activities(self):
  65. self.assertFalse(
  66. self.act1.team_id, 'Error: Activity 1 should not have a team.')
  67. self.assertEqual(self.team1.count_missing_activities, 1)
  68. self.team1.assign_team_to_unassigned_activities()
  69. self.team1._compute_missing_activities()
  70. self.assertEqual(self.team1.count_missing_activities, 0)
  71. self.assertEqual(self.act1.team_id, self.team1)
  72. def test_activity_onchanges(self):
  73. self.assertEqual(
  74. self.act2.team_id, self.team1,
  75. 'Error: Activity 2 should have Team 1.')
  76. with self.env.do_in_onchange():
  77. self.act2.team_id = False
  78. self.act2._onchange_team_id()
  79. self.assertEqual(self.act2.user_id, self.employee)
  80. self.act2.team_id = self.team2
  81. self.act2._onchange_team_id()
  82. self.assertEqual(self.act2.user_id, self.employee)
  83. self.act2.user_id = self.employee2
  84. self.act2._onchange_user_id()
  85. self.assertEqual(self.act2.team_id, self.team2)
  86. self.act2.team_id = self.team1
  87. self.act2._onchange_team_id()
  88. self.assertEqual(self.act2.user_id, self.team1.member_ids)
  89. with self.assertRaises(ValidationError):
  90. self.act2.write({
  91. 'user_id': self.employee2.id,
  92. 'team_id': self.team1.id,
  93. })
  94. def test_team_onchanges(self):
  95. self.assertFalse(
  96. self.team2.user_id,
  97. 'Error: Team 2 should not have a Team Leader yet.')
  98. with self.env.do_in_onchange():
  99. self.team2.user_id = self.employee
  100. self.team2.member_ids = [(3, self.employee.id)]
  101. self.team2._onchange_member_ids()
  102. self.assertFalse(self.team2.user_id)