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.

50 lines
1.8 KiB

  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  2. from odoo import exceptions
  3. from odoo.tests import common
  4. class TestCrmDeduplicateAcl(common.TransactionCase):
  5. def setUp(self):
  6. super(TestCrmDeduplicateAcl, self).setUp()
  7. self.partner_1 = self.env['res.partner'].create({
  8. 'name': 'Partner 1',
  9. 'email': 'partner1@example.org',
  10. 'is_company': True,
  11. 'parent_id': False,
  12. })
  13. self.partner_2 = self.partner_1.copy()
  14. self.partner_2.write({
  15. 'name': 'Partner 1',
  16. 'email': 'partner2@example.org'
  17. })
  18. self.user = self.env['res.users'].create({
  19. 'login': 'test_crm_deduplicate_acl',
  20. 'name': 'test_crm_deduplicate_acl',
  21. 'email': 'crm_deduplicate_acl@example.org',
  22. 'groups_id': [
  23. (4, self.env.ref('base.group_user').id),
  24. (4, self.env.ref('base.group_partner_manager').id),
  25. ]
  26. })
  27. self.wizard = self.env['base.partner.merge.automatic.wizard'].sudo(
  28. self.user,
  29. ).create({
  30. 'group_by_name': True,
  31. })
  32. def test_same_email_restriction(self):
  33. self.wizard.action_start_manual_process()
  34. with self.assertRaises(exceptions.UserError):
  35. self.wizard.action_merge()
  36. self.user.groups_id = [
  37. (4, self.env.ref('crm_deduplicate_acl.group_unrestricted').id),
  38. ]
  39. # Now there shouldn't be error
  40. self.wizard.action_merge()
  41. # Check that the posted message has correct user
  42. resulting_partner = (self.partner_1 + self.partner_2).exists()
  43. self.assertEqual(
  44. resulting_partner.message_ids[0].author_id,
  45. self.user.partner_id,
  46. )