2017-06-14 20:47:41 +02:00
|
|
|
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
|
|
|
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
|
|
|
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
2020-02-10 11:40:11 +01:00
|
|
|
# Copyright 2020 Tecnativa - Manuel Calero
|
2016-08-08 13:14:37 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
2015-08-28 11:15:50 +02:00
|
|
|
|
2018-05-17 22:00:43 +02:00
|
|
|
from odoo.exceptions import ValidationError
|
2015-08-28 11:15:50 +02:00
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
from ..hooks import post_init_hook
|
|
|
|
from . import base
|
2015-08-28 11:15:50 +02:00
|
|
|
|
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
class MailMassMailingContactCase(base.BaseCase):
|
2015-08-28 11:15:50 +02:00
|
|
|
def test_match_existing_contacts(self):
|
|
|
|
contact = self.create_mailing_contact(
|
2020-02-10 11:35:23 +01:00
|
|
|
{"email": "partner@test.com", "list_ids": [(6, 0, self.mailing_list.ids)]}
|
|
|
|
)
|
2016-08-08 13:14:37 +02:00
|
|
|
post_init_hook(self.cr, self.registry)
|
2015-08-28 11:15:50 +02:00
|
|
|
self.assertEqual(contact.partner_id.id, self.partner.id)
|
2018-05-17 22:00:43 +02:00
|
|
|
self.check_mailing_contact_partner(contact)
|
2015-08-28 11:15:50 +02:00
|
|
|
|
|
|
|
def test_create_mass_mailing_contact(self):
|
2020-02-10 11:35:23 +01:00
|
|
|
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
|
|
|
country_cu = self.env.ref("base.cu")
|
|
|
|
category_8 = self.env.ref("base.res_partner_category_8")
|
|
|
|
category_11 = self.env.ref("base.res_partner_category_11")
|
2018-05-17 22:00:43 +02:00
|
|
|
contact_vals = {
|
2020-02-10 11:35:23 +01:00
|
|
|
"name": "Partner test 2",
|
|
|
|
"email": "partner2@test.com",
|
|
|
|
"title_id": title_doctor.id,
|
|
|
|
"company_name": "TestCompany",
|
|
|
|
"country_id": country_cu.id,
|
|
|
|
"tag_ids": [(6, 0, (category_8 | category_11).ids)],
|
|
|
|
"list_ids": [(6, 0, (self.mailing_list | self.mailing_list2).ids)],
|
2018-05-17 22:00:43 +02:00
|
|
|
}
|
|
|
|
contact = self.create_mailing_contact(contact_vals)
|
2015-08-28 11:15:50 +02:00
|
|
|
self.check_mailing_contact_partner(contact)
|
2018-05-17 22:00:43 +02:00
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
self.create_mailing_contact(
|
2020-02-10 11:35:23 +01:00
|
|
|
{
|
|
|
|
"email": "partner2@test.com",
|
|
|
|
"list_ids": [[6, 0, [self.mailing_list2.id]]],
|
|
|
|
}
|
|
|
|
)
|
2015-08-28 11:15:50 +02:00
|
|
|
|
2018-11-09 13:24:39 +01:00
|
|
|
def test_create_mass_mailing_contact_with_subscription(self):
|
2020-02-10 11:35:23 +01:00
|
|
|
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
|
|
|
country_cu = self.env.ref("base.cu")
|
|
|
|
category_8 = self.env.ref("base.res_partner_category_8")
|
|
|
|
category_11 = self.env.ref("base.res_partner_category_11")
|
2018-11-09 13:24:39 +01:00
|
|
|
contact_vals = {
|
2020-02-10 11:35:23 +01:00
|
|
|
"name": "Partner test 2",
|
|
|
|
"email": "partner2@test.com",
|
|
|
|
"title_id": title_doctor.id,
|
|
|
|
"company_name": "TestCompany",
|
|
|
|
"country_id": country_cu.id,
|
|
|
|
"tag_ids": [(6, 0, (category_8 | category_11).ids)],
|
|
|
|
"subscription_list_ids": [
|
|
|
|
(0, 0, {"list_id": self.mailing_list.id}),
|
|
|
|
(0, 0, {"list_id": self.mailing_list2.id}),
|
2018-11-09 13:24:39 +01:00
|
|
|
],
|
|
|
|
}
|
|
|
|
contact = self.create_mailing_contact(contact_vals)
|
|
|
|
self.check_mailing_contact_partner(contact)
|
|
|
|
with self.assertRaises(ValidationError):
|
2020-02-10 11:35:23 +01:00
|
|
|
self.create_mailing_contact(
|
|
|
|
{
|
|
|
|
"email": "partner2@test.com",
|
|
|
|
"subscription_list_ids": [
|
|
|
|
(0, 0, {"list_id": self.mailing_list2.id})
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2018-11-09 13:24:39 +01:00
|
|
|
|
2015-08-28 11:15:50 +02:00
|
|
|
def test_write_mass_mailing_contact(self):
|
|
|
|
contact = self.create_mailing_contact(
|
2020-02-10 11:35:23 +01:00
|
|
|
{"email": "partner@test.com", "list_ids": [(6, 0, self.mailing_list.ids)]}
|
|
|
|
)
|
|
|
|
contact.write({"partner_id": False})
|
2015-08-28 11:15:50 +02:00
|
|
|
self.check_mailing_contact_partner(contact)
|
|
|
|
contact2 = self.create_mailing_contact(
|
2020-02-10 11:35:23 +01:00
|
|
|
{
|
|
|
|
"email": "partner2@test.com",
|
|
|
|
"name": "Partner test 2",
|
|
|
|
"list_ids": [(6, 0, self.mailing_list.ids)],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
contact2.write({"partner_id": False})
|
2015-08-28 11:15:50 +02:00
|
|
|
self.assertFalse(contact2.partner_id)
|
2016-08-08 13:14:37 +02:00
|
|
|
|
|
|
|
def test_onchange_partner(self):
|
|
|
|
contact = self.create_mailing_contact(
|
2020-02-10 11:35:23 +01:00
|
|
|
{"email": "partner@test.com", "list_ids": [[6, 0, [self.mailing_list.id]]]}
|
|
|
|
)
|
|
|
|
title_doctor = self.env.ref("base.res_partner_title_doctor")
|
|
|
|
country_cu = self.env.ref("base.cu")
|
|
|
|
category_8 = self.env.ref("base.res_partner_category_8")
|
|
|
|
category_11 = self.env.ref("base.res_partner_category_11")
|
2018-05-17 22:00:43 +02:00
|
|
|
partner_vals = {
|
2020-02-10 11:35:23 +01:00
|
|
|
"name": "Partner test 2",
|
|
|
|
"email": "partner2@test.com",
|
|
|
|
"title": title_doctor.id,
|
|
|
|
"company_id": self.main_company.id,
|
|
|
|
"country_id": country_cu.id,
|
|
|
|
"category_id": [(6, 0, (category_8 | category_11).ids)],
|
2018-05-17 22:00:43 +02:00
|
|
|
}
|
|
|
|
partner = self.create_partner(partner_vals)
|
2020-02-10 11:40:11 +01:00
|
|
|
contact.partner_id = partner
|
|
|
|
contact._onchange_partner_mass_mailing_partner()
|
|
|
|
self.check_mailing_contact_partner(contact)
|
2020-11-09 08:37:23 +01:00
|
|
|
|
|
|
|
def test_partners_merge(self):
|
|
|
|
partner_1 = self.create_partner({"name": "Demo 1", "email": "demo1@demo.com"})
|
|
|
|
partner_2 = self.create_partner({"name": "Demo 2", "email": "demo2@demo.com"})
|
|
|
|
list_1 = self.create_mailing_list({"name": "List test 1"})
|
|
|
|
list_2 = self.create_mailing_list({"name": "List test 2"})
|
|
|
|
contact_1 = self.create_mailing_contact(
|
|
|
|
{
|
|
|
|
"email": partner_1.email,
|
|
|
|
"name": partner_1.name,
|
|
|
|
"partner_id": partner_1.id,
|
|
|
|
"list_ids": [(6, 0, [list_1.id])],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
contact_2 = self.create_mailing_contact(
|
|
|
|
{
|
|
|
|
"email": partner_2.email,
|
|
|
|
"name": partner_2.name,
|
|
|
|
"partner_id": partner_2.id,
|
|
|
|
"list_ids": [(6, 0, [list_1.id, list_2.id])],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
# Wizard partner merge (partner_1 + partner_2) in partner_i1
|
|
|
|
wizard = self.env["base.partner.merge.automatic.wizard"].create(
|
|
|
|
{"state": "option"}
|
|
|
|
)
|
|
|
|
wizard._merge((partner_1 + partner_2).ids, partner_1)
|
|
|
|
contact = self.env["mailing.contact"].search(
|
|
|
|
[("id", "in", (contact_1 + contact_2).ids)]
|
|
|
|
)
|
|
|
|
self.assertEqual(len(contact), 1)
|
|
|
|
self.assertEqual(contact.list_ids.ids, (list_1 + list_2).ids)
|