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.

70 lines
3.2 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_4 = self.env.ref('base.res_partner_category_4')
  20. category_5 = self.env.ref('base.res_partner_category_5')
  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_4 | category_5).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_write_mass_mailing_contact(self):
  35. contact = self.create_mailing_contact(
  36. {'email': 'partner@test.com',
  37. 'list_ids': [(6, 0, self.mailing_list.ids)]})
  38. contact.write({'partner_id': False})
  39. self.check_mailing_contact_partner(contact)
  40. contact2 = self.create_mailing_contact(
  41. {'email': 'partner2@test.com', 'name': 'Partner test 2',
  42. 'list_ids': [(6, 0, self.mailing_list.ids)]})
  43. contact2.write({'partner_id': False})
  44. self.assertFalse(contact2.partner_id)
  45. def test_onchange_partner(self):
  46. contact = self.create_mailing_contact(
  47. {'email': 'partner@test.com',
  48. 'list_ids': [[6, 0, [self.mailing_list.id]]]})
  49. title_doctor = self.env.ref('base.res_partner_title_doctor')
  50. country_cu = self.env.ref('base.cu')
  51. category_4 = self.env.ref('base.res_partner_category_4')
  52. category_5 = self.env.ref('base.res_partner_category_5')
  53. partner_vals = {
  54. 'name': 'Partner test 2', 'email': 'partner2@test.com',
  55. 'title': title_doctor.id, 'company_id': self.main_company.id,
  56. 'country_id': country_cu.id,
  57. 'category_id': [(6, 0, (category_4 | category_5).ids)],
  58. }
  59. partner = self.create_partner(partner_vals)
  60. with self.env.do_in_onchange():
  61. contact.partner_id = partner
  62. contact._onchange_partner_mass_mailing_partner()
  63. self.check_mailing_contact_partner(contact)