Browse Source

[MIG] mass_mailing_event: Migration to 10.0

pull/173/head
David Vidal 8 years ago
parent
commit
01ad13ec11
  1. 5
      mass_mailing_event/README.rst
  2. 1
      mass_mailing_event/__init__.py
  3. 26
      mass_mailing_event/__manifest__.py
  4. 24
      mass_mailing_event/__openerp__.py
  5. 4
      mass_mailing_event/data/event_state_data.xml
  6. 3
      mass_mailing_event/models/__init__.py
  7. 4
      mass_mailing_event/models/event_registration.py
  8. 2
      mass_mailing_event/models/event_registration_state.py
  9. 12
      mass_mailing_event/models/mail_mass_mailing.py
  10. 4
      mass_mailing_event/models/mail_mass_mailing_contact.py
  11. 4
      mass_mailing_event/models/res_partner.py
  12. 1
      mass_mailing_event/tests/__init__.py
  13. 126
      mass_mailing_event/tests/test_mass_mailing_event.py
  14. 6
      mass_mailing_event/views/mass_mailing_view.xml

5
mass_mailing_event/README.rst

@ -32,7 +32,7 @@ event yet.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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 Bug Tracker
@ -41,7 +41,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please <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, 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 Credits
======= =======
@ -55,6 +55,7 @@ Contributors
------------ ------------
* Antonio Espinosa <antonio.espinosa@tecnativa.com> * Antonio Espinosa <antonio.espinosa@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
Maintainer Maintainer
---------- ----------

1
mass_mailing_event/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models from . import models

26
mass_mailing_event/__manifest__.py

@ -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',
],
}

24
mass_mailing_event/__openerp__.py

@ -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",
],
}

4
mass_mailing_event/data/event_state_data.xml

@ -2,7 +2,7 @@
<!-- Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> <!-- Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<odoo>
<data> <data>
<record id="event_draft" model="event.registration.state"> <record id="event_draft" model="event.registration.state">
@ -26,4 +26,4 @@
</record> </record>
</data> </data>
</openerp>
</odoo>

3
mass_mailing_event/models/__init__.py

@ -1,8 +1,7 @@
# -*- coding: utf-8 -*- # -*- 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 event_registration_state
from . import mail_mass_mailing from . import mail_mass_mailing
from . import mail_mass_mailing_contact from . import mail_mass_mailing_contact
from . import res_partner from . import res_partner
from . import event_registration

4
mass_mailing_event/models/event_registration.py

@ -2,7 +2,7 @@
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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 from .mail_mass_mailing import event_filtered_ids
@ -16,5 +16,5 @@ class EventRegistration(models.Model):
if mass_mailing_id: if mass_mailing_id:
res_ids = event_filtered_ids( res_ids = event_filtered_ids(
self, mass_mailing_id, domain, field='email') 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 return res

2
mass_mailing_event/models/event_registration_state.py

@ -2,7 +2,7 @@
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class EventRegistrationState(models.Model):

12
mass_mailing_event/models/mail_mass_mailing.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import copy import copy
from openerp import models, fields, api
from odoo import fields, models
def event_filtered_ids(model, mass_mailing_id, domain, field='email'): def event_filtered_ids(model, mass_mailing_id, domain, field='email'):
@ -43,12 +43,10 @@ class MailMassMailing(models.Model):
comodel_name='event.registration.state', comodel_name='event.registration.state',
string="Exclude", default=_default_exclude_event_state_ids) 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: if res_ids:
domain = [('id', 'in', 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 return res_ids

4
mass_mailing_event/models/mail_mass_mailing_contact.py

@ -2,7 +2,7 @@
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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 from .mail_mass_mailing import event_filtered_ids
@ -16,5 +16,5 @@ class MailMassMailingContact(models.Model):
if mass_mailing_id: if mass_mailing_id:
res_ids = event_filtered_ids( res_ids = event_filtered_ids(
self, mass_mailing_id, domain, field='email') 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 return res

4
mass_mailing_event/models/res_partner.py

@ -2,7 +2,7 @@
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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 from .mail_mass_mailing import event_filtered_ids
@ -16,5 +16,5 @@ class ResPartner(models.Model):
if mass_mailing_id: if mass_mailing_id:
res_ids = event_filtered_ids( res_ids = event_filtered_ids(
self, mass_mailing_id, domain, field='email') 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 return res

1
mass_mailing_event/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_mass_mailing_event from . import test_mass_mailing_event

126
mass_mailing_event/tests/test_mass_mailing_event.py

@ -1,51 +1,54 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # 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). # 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', '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', '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', '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', 'name': 'Test contact A',
'email': 'partner_a@example.org', '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', 'name': 'Test contact B',
'email': 'partner_b@example.org', '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 = [ domain = [
('list_id', 'in', [contact_list.id]),
('list_id', 'in', [self.contact_list.id]),
('opt_out', '=', False), ('opt_out', '=', False),
] ]
mass_mailing = self.env['mail.mass_mailing'].create({ mass_mailing = self.env['mail.mass_mailing'].create({
@ -53,45 +56,41 @@ class TestMassMailingEvent(TransactionCase):
'email_from': 'from@example.com', 'email_from': 'from@example.com',
'mailing_model': 'mail.mass_mailing.contact', 'mailing_model': 'mail.mass_mailing.contact',
'mailing_domain': str(domain), '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>', 'body_html': '<p>Test email body</p>',
'reply_to_mode': 'email', '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) exclude_mass_mailing=mass_mailing.id)
self.assertEqual( 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({ mass_mailing.write({
'event_id': self.event.id, '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( 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({ 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( 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): 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 = [ domain = [
('id', 'in', [partner_a.id, partner_b.id]),
('id', 'in', [self.partner_a.id, self.partner_b.id]),
('opt_out', '=', False), ('opt_out', '=', False),
] ]
domain_reg = [
('event_id', '=', self.event.id),
]
mass_mailing = self.env['mail.mass_mailing'].create({ mass_mailing = self.env['mail.mass_mailing'].create({
'name': 'Test subject', 'name': 'Test subject',
'email_from': 'from@example.com', 'email_from': 'from@example.com',
@ -100,24 +99,29 @@ class TestMassMailingEvent(TransactionCase):
'body_html': '<p>Test email body</p>', 'body_html': '<p>Test email body</p>',
'reply_to_mode': 'email', '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) exclude_mass_mailing=mass_mailing.id)
self.assertEqual( 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({ mass_mailing.write({
'event_id': self.event.id, '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( 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({ 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( 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))

6
mass_mailing_event/views/mass_mailing_view.xml

@ -2,8 +2,7 @@
<!-- Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> <!-- Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> 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"> <record model="ir.ui.view" id="view_mail_mass_mailing_form">
<field name="name">Add event and exclude</field> <field name="name">Add event and exclude</field>
@ -29,5 +28,4 @@
</field> </field>
</record> </record>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save