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.

95 lines
4.3 KiB

  1. # Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  2. # Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  3. # Copyright 2015 Javier Iniesta <javieria@antiun.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from . import base
  6. from ..hooks import post_init_hook
  7. from odoo.exceptions import ValidationError
  8. class MailMassMailingContactCase(base.BaseCase):
  9. def test_match_existing_contacts(self):
  10. contact = self.create_mailing_contact(
  11. {'email': 'partner@test.com',
  12. 'list_ids': [(6, 0, self.mailing_list.ids)]})
  13. post_init_hook(self.cr, self.registry)
  14. self.assertEqual(contact.partner_id.id, self.partner.id)
  15. self.check_mailing_contact_partner(contact)
  16. def test_create_mass_mailing_contact(self):
  17. title_doctor = self.env.ref('base.res_partner_title_doctor')
  18. country_cu = self.env.ref('base.cu')
  19. category_8 = self.env.ref('base.res_partner_category_8')
  20. category_11 = self.env.ref('base.res_partner_category_11')
  21. contact_vals = {
  22. 'name': 'Partner test 2', 'email': 'partner2@test.com',
  23. 'title_id': title_doctor.id, 'company_name': "TestCompany",
  24. 'country_id': country_cu.id,
  25. 'tag_ids': [(6, 0, (category_8 | category_11).ids)],
  26. 'list_ids': [(6, 0, (self.mailing_list | self.mailing_list2).ids)],
  27. }
  28. contact = self.create_mailing_contact(contact_vals)
  29. self.check_mailing_contact_partner(contact)
  30. with self.assertRaises(ValidationError):
  31. self.create_mailing_contact(
  32. {'email': 'partner2@test.com',
  33. 'list_ids': [[6, 0, [self.mailing_list2.id]]]})
  34. def test_create_mass_mailing_contact_with_subscription(self):
  35. title_doctor = self.env.ref('base.res_partner_title_doctor')
  36. country_cu = self.env.ref('base.cu')
  37. category_8 = self.env.ref('base.res_partner_category_8')
  38. category_11 = self.env.ref('base.res_partner_category_11')
  39. contact_vals = {
  40. 'name': 'Partner test 2', 'email': 'partner2@test.com',
  41. 'title_id': title_doctor.id, 'company_name': "TestCompany",
  42. 'country_id': country_cu.id,
  43. 'tag_ids': [(6, 0, (category_8 | category_11).ids)],
  44. 'subscription_list_ids': [
  45. (0, 0, {'list_id': self.mailing_list.id}),
  46. (0, 0, {'list_id': self.mailing_list2.id}),
  47. ],
  48. }
  49. contact = self.create_mailing_contact(contact_vals)
  50. self.check_mailing_contact_partner(contact)
  51. with self.assertRaises(ValidationError):
  52. self.create_mailing_contact({
  53. 'email': 'partner2@test.com',
  54. 'subscription_list_ids': [
  55. (0, 0, {'list_id': self.mailing_list2.id}),
  56. ],
  57. })
  58. def test_write_mass_mailing_contact(self):
  59. contact = self.create_mailing_contact(
  60. {'email': 'partner@test.com',
  61. 'list_ids': [(6, 0, self.mailing_list.ids)]})
  62. contact.write({'partner_id': False})
  63. self.check_mailing_contact_partner(contact)
  64. contact2 = self.create_mailing_contact(
  65. {'email': 'partner2@test.com', 'name': 'Partner test 2',
  66. 'list_ids': [(6, 0, self.mailing_list.ids)]})
  67. contact2.write({'partner_id': False})
  68. self.assertFalse(contact2.partner_id)
  69. def test_onchange_partner(self):
  70. contact = self.create_mailing_contact(
  71. {'email': 'partner@test.com',
  72. 'list_ids': [[6, 0, [self.mailing_list.id]]]})
  73. title_doctor = self.env.ref('base.res_partner_title_doctor')
  74. country_cu = self.env.ref('base.cu')
  75. category_8 = self.env.ref('base.res_partner_category_8')
  76. category_11 = self.env.ref('base.res_partner_category_11')
  77. partner_vals = {
  78. 'name': 'Partner test 2', 'email': 'partner2@test.com',
  79. 'title': title_doctor.id, 'company_id': self.main_company.id,
  80. 'country_id': country_cu.id,
  81. 'category_id': [(6, 0, (category_8 | category_11).ids)],
  82. }
  83. partner = self.create_partner(partner_vals)
  84. with self.env.do_in_onchange():
  85. contact.partner_id = partner
  86. contact._onchange_partner_mass_mailing_partner()
  87. self.check_mailing_contact_partner(contact)