mirror of https://github.com/OCA/social.git
[MIG] mass_mailing_event: Migration to 10.0
parent
929375ff0c
commit
7d701f1a23
|
@ -32,7 +32,7 @@ event yet.
|
|||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/205/8.0
|
||||
:target: https://runbot.odoo-community.org/runbot/205/10.0
|
||||
|
||||
|
||||
Bug Tracker
|
||||
|
@ -41,7 +41,7 @@ Bug Tracker
|
|||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/social/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
help us smash it by providing detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
@ -55,6 +55,7 @@ Contributors
|
|||
------------
|
||||
|
||||
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
* David Vidal <david.vidal@tecnativa.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Mass mailing event',
|
||||
'summary': 'Link mass mailing with event for excluding recipients',
|
||||
'version': '10.0.1.0.0',
|
||||
'category': 'Marketing',
|
||||
'website': 'https://www.tecnativa.com',
|
||||
'author': 'Tecnativa, '
|
||||
'Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'application': False,
|
||||
'installable': True,
|
||||
'depends': [
|
||||
'mass_mailing',
|
||||
'event',
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'data/event_state_data.xml',
|
||||
'views/mass_mailing_view.xml',
|
||||
],
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "Mass mailing event",
|
||||
"summary": "Link mass mailing with event for excluding recipients",
|
||||
"version": "8.0.1.0.0",
|
||||
"category": "Marketing",
|
||||
"website": "https://odoo-community.org/",
|
||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"application": False,
|
||||
"installable": True,
|
||||
"depends": [
|
||||
"mass_mailing",
|
||||
"event",
|
||||
],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"data/event_state_data.xml",
|
||||
"views/mass_mailing_view.xml",
|
||||
],
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
<!-- Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<openerp>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record id="event_draft" model="event.registration.state">
|
||||
|
@ -26,4 +26,4 @@
|
|||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import event_registration
|
||||
from . import event_registration_state
|
||||
from . import mail_mass_mailing
|
||||
from . import mail_mass_mailing_contact
|
||||
from . import res_partner
|
||||
from . import event_registration
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, api
|
||||
from odoo import api, models
|
||||
from .mail_mass_mailing import event_filtered_ids
|
||||
|
||||
|
||||
|
@ -16,5 +16,5 @@ class EventRegistration(models.Model):
|
|||
if mass_mailing_id:
|
||||
res_ids = event_filtered_ids(
|
||||
self, mass_mailing_id, domain, field='email')
|
||||
return len(res_ids) if res_ids else 0
|
||||
res = len(res_ids) if res_ids else 0
|
||||
return res
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, fields
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class EventRegistrationState(models.Model):
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import copy
|
||||
from openerp import models, fields, api
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
def event_filtered_ids(model, mass_mailing_id, domain, field='email'):
|
||||
|
@ -43,12 +43,10 @@ class MailMassMailing(models.Model):
|
|||
comodel_name='event.registration.state',
|
||||
string="Exclude", default=_default_exclude_event_state_ids)
|
||||
|
||||
@api.model
|
||||
def get_recipients(self, mailing):
|
||||
res_ids = super(MailMassMailing, self).get_recipients(mailing)
|
||||
def get_recipients(self):
|
||||
res_ids = super(MailMassMailing, self).get_recipients()
|
||||
if res_ids:
|
||||
domain = [('id', 'in', res_ids)]
|
||||
return event_filtered_ids(
|
||||
self.env[mailing.mailing_model], mailing.id, domain,
|
||||
field='email')
|
||||
res_ids = event_filtered_ids(
|
||||
self.env[self.mailing_model], self.id, domain, field='email')
|
||||
return res_ids
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, api
|
||||
from odoo import api, models
|
||||
from .mail_mass_mailing import event_filtered_ids
|
||||
|
||||
|
||||
|
@ -16,5 +16,5 @@ class MailMassMailingContact(models.Model):
|
|||
if mass_mailing_id:
|
||||
res_ids = event_filtered_ids(
|
||||
self, mass_mailing_id, domain, field='email')
|
||||
return len(res_ids) if res_ids else 0
|
||||
res = len(res_ids) if res_ids else 0
|
||||
return res
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, api
|
||||
from odoo import api, models
|
||||
from .mail_mass_mailing import event_filtered_ids
|
||||
|
||||
|
||||
|
@ -16,5 +16,5 @@ class ResPartner(models.Model):
|
|||
if mass_mailing_id:
|
||||
res_ids = event_filtered_ids(
|
||||
self, mass_mailing_id, domain, field='email')
|
||||
return len(res_ids) if res_ids else 0
|
||||
res = len(res_ids) if res_ids else 0
|
||||
return res
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import test_mass_mailing_event
|
||||
|
|
|
@ -1,51 +1,54 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from openerp.tests.common import TransactionCase
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestMassMailingEvent(TransactionCase):
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestMassMailingEvent, self).setUp(*args, **kwargs)
|
||||
class TestMassMailingEvent(common.SavepointCase):
|
||||
|
||||
day_1 = (datetime.now() + timedelta(days=1)).strftime(
|
||||
'%Y-%m-%d 8:00:00')
|
||||
day_2 = (datetime.now() + timedelta(days=5)).strftime(
|
||||
'%Y-%m-%d 18:00:00')
|
||||
self.event = self.env['event.event'].create({
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestMassMailingEvent, cls).setUpClass()
|
||||
cls.event = cls.env['event.event'].create({
|
||||
'name': 'Test event',
|
||||
'date_begin': day_1,
|
||||
'date_end': day_2,
|
||||
'date_begin': '2017-06-24 8:00:00',
|
||||
'date_end': '2017-06-30 18:00:00',
|
||||
})
|
||||
self.registration = self.env['event.registration'].create({
|
||||
'event_id': self.event.id,
|
||||
cls.registration = cls.env['event.registration'].create({
|
||||
'event_id': cls.event.id,
|
||||
'email': 'partner_a@example.org',
|
||||
'nb_register': 1,
|
||||
'state': 'draft',
|
||||
})
|
||||
self.states_all = self.env['event.registration.state'].search([])
|
||||
self.state_confirmed = self.env['event.registration.state'].search([
|
||||
('code', '=', 'open'),
|
||||
cls.states_all = cls.env['event.registration.state'].search([])
|
||||
cls.state_confirmed = cls.env['event.registration.state'].search([
|
||||
('code', '=', 'open')
|
||||
])
|
||||
|
||||
def test_mailing_contact(self):
|
||||
contact_list = self.env['mail.mass_mailing.list'].create({
|
||||
cls.contact_list = cls.env['mail.mass_mailing.list'].create({
|
||||
'name': 'Test list',
|
||||
})
|
||||
contact_a = self.env['mail.mass_mailing.contact'].create({
|
||||
'list_id': contact_list.id,
|
||||
cls.contact_a = cls.env['mail.mass_mailing.contact'].create({
|
||||
'list_id': cls.contact_list.id,
|
||||
'name': 'Test contact A',
|
||||
'email': 'partner_a@example.org',
|
||||
})
|
||||
contact_b = self.env['mail.mass_mailing.contact'].create({
|
||||
'list_id': contact_list.id,
|
||||
cls.contact_b = cls.env['mail.mass_mailing.contact'].create({
|
||||
'list_id': cls.contact_list.id,
|
||||
'name': 'Test contact B',
|
||||
'email': 'partner_b@example.org',
|
||||
})
|
||||
cls.partner_a = cls.env['res.partner'].create({
|
||||
'name': 'Test partner A',
|
||||
'email': 'partner_a@example.org',
|
||||
})
|
||||
cls.partner_b = cls.env['res.partner'].create({
|
||||
'name': 'Test partner B',
|
||||
'email': 'partner_b@example.org',
|
||||
})
|
||||
|
||||
def test_mailing_contact(self):
|
||||
domain = [
|
||||
('list_id', 'in', [contact_list.id]),
|
||||
('list_id', 'in', [self.contact_list.id]),
|
||||
('opt_out', '=', False),
|
||||
]
|
||||
mass_mailing = self.env['mail.mass_mailing'].create({
|
||||
|
@ -53,45 +56,41 @@ class TestMassMailingEvent(TransactionCase):
|
|||
'email_from': 'from@example.com',
|
||||
'mailing_model': 'mail.mass_mailing.contact',
|
||||
'mailing_domain': str(domain),
|
||||
'contact_list_ids': [(6, False, [contact_list.id])],
|
||||
'contact_list_ids': [(6, 0, [self.contact_list.id])],
|
||||
'body_html': '<p>Test email body</p>',
|
||||
'reply_to_mode': 'email',
|
||||
})
|
||||
m_contact = self.env['mail.mass_mailing.contact'].with_context(
|
||||
mail_contact = self.env['mail.mass_mailing.contact'].with_context(
|
||||
exclude_mass_mailing=mass_mailing.id)
|
||||
self.assertEqual(
|
||||
[contact_a.id, contact_b.id],
|
||||
mass_mailing.get_recipients(mass_mailing))
|
||||
self.assertEqual(2, m_contact.search_count(domain))
|
||||
[self.contact_a.id, self.contact_b.id],
|
||||
mass_mailing.get_recipients())
|
||||
self.assertEqual(2, mail_contact.search_count(domain))
|
||||
mass_mailing.write({
|
||||
'event_id': self.event.id,
|
||||
'exclude_event_state_ids': [(6, False, self.states_all.ids)],
|
||||
'exclude_event_state_ids': [(6, 0, self.states_all.ids)],
|
||||
})
|
||||
self.assertEqual(
|
||||
[contact_b.id],
|
||||
mass_mailing.get_recipients(mass_mailing))
|
||||
self.assertEqual(1, m_contact.search_count(domain))
|
||||
[self.contact_b.id],
|
||||
mass_mailing.get_recipients())
|
||||
self.assertEqual(1, mail_contact.search_count(domain))
|
||||
self.registration.state = 'draft'
|
||||
mass_mailing.write({
|
||||
'exclude_event_state_ids': [(6, False, self.state_confirmed.ids)],
|
||||
'exclude_event_state_ids': [(6, 0, self.state_confirmed.ids)],
|
||||
})
|
||||
self.assertEqual(
|
||||
[contact_a.id, contact_b.id],
|
||||
mass_mailing.get_recipients(mass_mailing))
|
||||
self.assertEqual(2, m_contact.search_count(domain))
|
||||
[self.contact_a.id, self.contact_b.id],
|
||||
mass_mailing.get_recipients())
|
||||
self.assertEqual(2, mail_contact.search_count(domain))
|
||||
|
||||
def test_mailing_partner(self):
|
||||
partner_a = self.env['res.partner'].create({
|
||||
'name': 'Test partner A',
|
||||
'email': 'partner_a@example.org',
|
||||
})
|
||||
partner_b = self.env['res.partner'].create({
|
||||
'name': 'Test partner B',
|
||||
'email': 'partner_b@example.org',
|
||||
})
|
||||
domain = [
|
||||
('id', 'in', [partner_a.id, partner_b.id]),
|
||||
('id', 'in', [self.partner_a.id, self.partner_b.id]),
|
||||
('opt_out', '=', False),
|
||||
]
|
||||
domain_reg = [
|
||||
('event_id', '=', self.event.id),
|
||||
]
|
||||
mass_mailing = self.env['mail.mass_mailing'].create({
|
||||
'name': 'Test subject',
|
||||
'email_from': 'from@example.com',
|
||||
|
@ -100,24 +99,29 @@ class TestMassMailingEvent(TransactionCase):
|
|||
'body_html': '<p>Test email body</p>',
|
||||
'reply_to_mode': 'email',
|
||||
})
|
||||
m_partner = self.env['res.partner'].with_context(
|
||||
mail_partner = self.env['res.partner'].with_context(
|
||||
exclude_mass_mailing=mass_mailing.id)
|
||||
mail_registration = self.env['event.registration'].with_context(
|
||||
exclude_mass_mailing=mass_mailing.id)
|
||||
self.assertEqual(
|
||||
[partner_a.id, partner_b.id],
|
||||
mass_mailing.get_recipients(mass_mailing))
|
||||
self.assertEqual(2, m_partner.search_count(domain))
|
||||
[self.partner_a.id, self.partner_b.id],
|
||||
mass_mailing.get_recipients())
|
||||
self.assertEqual(2, mail_partner.search_count(domain))
|
||||
mass_mailing.write({
|
||||
'event_id': self.event.id,
|
||||
'exclude_event_state_ids': [(6, False, self.states_all.ids)],
|
||||
'exclude_event_state_ids': [(6, 0, self.states_all.ids)],
|
||||
})
|
||||
self.assertEqual(
|
||||
[partner_b.id],
|
||||
mass_mailing.get_recipients(mass_mailing))
|
||||
self.assertEqual(1, m_partner.search_count(domain))
|
||||
[self.partner_b.id],
|
||||
mass_mailing.get_recipients())
|
||||
self.assertEqual(1, mail_partner.search_count(domain))
|
||||
self.assertEqual(0, mail_registration.search_count(domain_reg))
|
||||
self.registration.state = 'draft'
|
||||
mass_mailing.write({
|
||||
'exclude_event_state_ids': [(6, False, self.state_confirmed.ids)],
|
||||
'exclude_event_state_ids': [(6, 0, self.state_confirmed.ids)],
|
||||
})
|
||||
self.assertEqual(
|
||||
[partner_a.id, partner_b.id],
|
||||
mass_mailing.get_recipients(mass_mailing))
|
||||
self.assertEqual(2, m_partner.search_count(domain))
|
||||
[self.partner_a.id, self.partner_b.id],
|
||||
mass_mailing.get_recipients())
|
||||
self.assertEqual(2, mail_partner.search_count(domain))
|
||||
self.assertEqual(1, mail_registration.search_count(domain_reg))
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
<!-- Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_form">
|
||||
<field name="name">Add event and exclude</field>
|
||||
|
@ -29,5 +28,4 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue