test_res_partner.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.tests.common import TransactionCase
  4. from odoo.tests.common import new_test_user
  5. class TestResPartner(TransactionCase):
  6. def test_meeting_count(self):
  7. test_user = new_test_user(self.env, login='test_user', groups='base.group_user, base.group_partner_manager')
  8. Partner = self.env['res.partner'].with_user(test_user)
  9. Event = self.env['calendar.event'].with_user(test_user)
  10. # Partner hierarchy
  11. # 1 5
  12. # /|
  13. # 2 3
  14. # |
  15. # 4
  16. test_partner_1 = Partner.create({'name': 'test_partner_1'})
  17. test_partner_2 = Partner.create({'name': 'test_partner_2', 'parent_id': test_partner_1.id})
  18. test_partner_3 = Partner.create({'name': 'test_partner_3', 'parent_id': test_partner_1.id})
  19. test_partner_4 = Partner.create({'name': 'test_partner_4', 'parent_id': test_partner_3.id})
  20. test_partner_5 = Partner.create({'name': 'test_partner_5'})
  21. Event.create({'name': 'event_1',
  22. 'partner_ids': [(6, 0, [test_partner_1.id,
  23. test_partner_2.id,
  24. test_partner_3.id,
  25. test_partner_4.id])]})
  26. Event.create({'name': 'event_2',
  27. 'partner_ids': [(6, 0, [test_partner_1.id,
  28. test_partner_3.id])]})
  29. Event.create({'name': 'event_2',
  30. 'partner_ids': [(6, 0, [test_partner_2.id,
  31. test_partner_3.id])]})
  32. Event.create({'name': 'event_3',
  33. 'partner_ids': [(6, 0, [test_partner_3.id,
  34. test_partner_4.id])]})
  35. Event.create({'name': 'event_4',
  36. 'partner_ids': [(6, 0, [test_partner_1.id])]})
  37. Event.create({'name': 'event_5',
  38. 'partner_ids': [(6, 0, [test_partner_3.id])]})
  39. Event.create({'name': 'event_6',
  40. 'partner_ids': [(6, 0, [test_partner_4.id])]})
  41. Event.create({'name': 'event_7',
  42. 'partner_ids': [(6, 0, [test_partner_5.id])]})
  43. Event.create({'name': 'event_8',
  44. 'partner_ids': [(6, 0, [test_partner_5.id])]})
  45. #Test rule to see if ir.rules are applied
  46. calendar_event_model_id = self.env['ir.model']._get('calendar.event').id
  47. self.env['ir.rule'].create({'name': 'test_rule',
  48. 'model_id': calendar_event_model_id,
  49. 'domain_force': [('name', 'not in', ['event_9', 'event_10'])],
  50. 'perm_read': True,
  51. 'perm_create': False,
  52. 'perm_write': False})
  53. Event.create({'name': 'event_9',
  54. 'partner_ids': [(6, 0, [test_partner_2.id,
  55. test_partner_3.id])]})
  56. Event.create({'name': 'event_10',
  57. 'partner_ids': [(6, 0, [test_partner_5.id])]})
  58. self.assertEqual(test_partner_1.meeting_count, 7)
  59. self.assertEqual(test_partner_2.meeting_count, 2)
  60. self.assertEqual(test_partner_3.meeting_count, 6)
  61. self.assertEqual(test_partner_4.meeting_count, 3)
  62. self.assertEqual(test_partner_5.meeting_count, 2)