Sergio Teruel
6 years ago
committed by
Pedro M. Baeza
15 changed files with 171 additions and 29 deletions
-
10mass_mailing_partner/README.rst
-
2mass_mailing_partner/__manifest__.py
-
1mass_mailing_partner/models/__init__.py
-
18mass_mailing_partner/models/mail_mass_mailing.py
-
15mass_mailing_partner/models/mail_mass_mailing_contact.py
-
18mass_mailing_partner/models/mail_mass_mailing_list_contact_rel.py
-
4mass_mailing_partner/models/res_partner.py
-
6mass_mailing_partner/static/description/index.html
-
2mass_mailing_partner/tests/__init__.py
-
4mass_mailing_partner/tests/base.py
-
37mass_mailing_partner/tests/test_mail_mass_mailing_contact.py
-
41mass_mailing_partner/tests/test_mail_mass_mailing_list.py
-
30mass_mailing_partner/tests/test_mail_mass_mailing_list_contact_rel.py
-
6mass_mailing_partner/tests/test_res_partner.py
-
4mass_mailing_partner/views/mail_mass_mailing_contact_view.xml
@ -0,0 +1,18 @@ |
|||
# Copyright 2018 Tecnativa - Ernesto Tejeda |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from odoo import api, models, _ |
|||
from odoo.exceptions import ValidationError |
|||
|
|||
|
|||
class MassMailingContactListRel(models.Model): |
|||
_inherit = 'mail.mass_mailing.list_contact_rel' |
|||
|
|||
@api.constrains('contact_id', 'list_id') |
|||
def _check_contact_id_partner_id_list_id(self): |
|||
for rel in self: |
|||
if rel.contact_id.partner_id: |
|||
contacts = rel.list_id.contact_ids - rel.contact_id |
|||
if rel.contact_id.partner_id in contacts.mapped('partner_id'): |
|||
raise ValidationError(_("A partner cannot be multiple " |
|||
"times in the same list")) |
@ -0,0 +1,41 @@ |
|||
# Copyright 2018 Tecnativa - Ernesto tejeda |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import base |
|||
from odoo.exceptions import ValidationError |
|||
|
|||
|
|||
class MailMassMailingListCase(base.BaseCase): |
|||
|
|||
def test_create_mass_mailing_list(self): |
|||
contact_test_1 = self.create_mailing_contact({ |
|||
'name': 'Contact test 1', |
|||
'partner_id': self.partner.id, |
|||
}) |
|||
contact_test_2 = self.create_mailing_contact({ |
|||
'name': 'Contact test 2', |
|||
'partner_id': self.partner.id, |
|||
}) |
|||
with self.assertRaises(ValidationError): |
|||
self.create_mailing_list({ |
|||
'name': 'List test 3', |
|||
'contact_ids': [(6, 0, (contact_test_1 | contact_test_2).ids)] |
|||
}) |
|||
|
|||
def test_create_mass_mailing_list_with_subscription(self): |
|||
contact_test_1 = self.create_mailing_contact({ |
|||
'name': 'Contact test 1', |
|||
'partner_id': self.partner.id, |
|||
}) |
|||
contact_test_2 = self.create_mailing_contact({ |
|||
'name': 'Contact test 2', |
|||
'partner_id': self.partner.id, |
|||
}) |
|||
with self.assertRaises(ValidationError): |
|||
self.create_mailing_list({ |
|||
'name': 'List test 3', |
|||
'subscription_contact_ids': [ |
|||
(0, 0, {'contact_id': contact_test_1.id}), |
|||
(0, 0, {'contact_id': contact_test_2.id}), |
|||
] |
|||
}) |
@ -0,0 +1,30 @@ |
|||
# Copyright 2018 Tecnativa - Ernesto tejeda |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import base |
|||
from odoo.exceptions import ValidationError |
|||
|
|||
|
|||
class MailMassMailingListContactRelCase(base.BaseCase): |
|||
|
|||
def test_create_mass_mailing_list(self): |
|||
contact_test_1 = self.create_mailing_contact({ |
|||
'name': 'Contact test 1', |
|||
'partner_id': self.partner.id, |
|||
}) |
|||
contact_test_2 = self.create_mailing_contact({ |
|||
'name': 'Contact test 2', |
|||
'partner_id': self.partner.id, |
|||
}) |
|||
list_3 = self.create_mailing_list({'name': 'List test 3'}) |
|||
|
|||
self.env['mail.mass_mailing.list_contact_rel'].create({ |
|||
'list_id': list_3.id, |
|||
'contact_id': contact_test_1.id, |
|||
}) |
|||
|
|||
with self.assertRaises(ValidationError): |
|||
self.env['mail.mass_mailing.list_contact_rel'].create({ |
|||
'list_id': list_3.id, |
|||
'contact_id': contact_test_2.id, |
|||
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue