Skip to content

Commit

Permalink
mass_mailing_event (OCA#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
antespi authored and chienandalu committed Aug 30, 2017
1 parent b9e0602 commit b9e0f57
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 0 deletions.
72 changes: 72 additions & 0 deletions mass_mailing_event/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

==================
Mass mailing event
==================

This module links ``mass_mailing`` with ``event`` in order to exclude
recipients that are already registered, confirmed, cancelled, attended, or a
combination of these states, when the mass mailing is sent.

Usage
=====

In a mass mailing, users can set an event related and exclude the recipients who
have an email address already registered in that event.

This is useful in this scenario:

1. Create a mass mailing for telling to 1000 partners that a new event is
available.
2. During a week some of them (50) have been registered in the event
3. Then, a week after the first mass mailing, duplicate it to get a second
mass mailing. Relate this one to the event and exclude the registered emails.
Change the message body to remember that early bird period is going to expire
soon.
4. Send the second mass mailing and registered emails are automatically excluded,
So it's been only sent to 950 partners the ones who are not registered in the
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


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.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Antonio Espinosa <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
4 changes: 4 additions & 0 deletions mass_mailing_event/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
24 changes: 24 additions & 0 deletions mass_mailing_event/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <[email protected]>
# 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",
],
}
29 changes: 29 additions & 0 deletions mass_mailing_event/data/event_state_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Antonio Espinosa <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<openerp>
<data>

<record id="event_draft" model="event.registration.state">
<field name="name">Unconfirmed</field>
<field name="code">draft</field>
</record>

<record id="event_cancel" model="event.registration.state">
<field name="name">Cancelled</field>
<field name="code">cancel</field>
</record>

<record id="event_open" model="event.registration.state">
<field name="name">Confirmed</field>
<field name="code">open</field>
</record>

<record id="event_done" model="event.registration.state">
<field name="name">Attended</field>
<field name="code">done</field>
</record>

</data>
</openerp>
96 changes: 96 additions & 0 deletions mass_mailing_event/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mass_mailing_event
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-11-07 11:16+0000\n"
"PO-Revision-Date: 2016-11-07 11:16+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mass_mailing_event
#: field:event.registration.state,code:0
msgid "Code"
msgstr "Código"

#. module: mass_mailing_event
#: field:event.registration.state,create_uid:0
msgid "Created by"
msgstr "Creado por"

#. module: mass_mailing_event
#: field:event.registration.state,create_date:0
msgid "Created on"
msgstr "Creado en"

#. module: mass_mailing_event
#: field:event.registration.state,display_name:0
msgid "Display Name"
msgstr "Nombre mostrado"

#. module: mass_mailing_event
#: model:ir.model,name:mass_mailing_event.model_event_registration
msgid "Event Registration"
msgstr "Registro de evento"

#. module: mass_mailing_event
#: field:mail.mass_mailing,event_id:0
msgid "Event related"
msgstr "Evento relacionado"

#. module: mass_mailing_event
#: field:mail.mass_mailing,exclude_event_state_ids:0
msgid "Exclude"
msgstr "Excluir"

#. module: mass_mailing_event
#: field:event.registration.state,id:0
msgid "ID"
msgstr "ID"

#. module: mass_mailing_event
#: field:event.registration.state,__last_update:0
msgid "Last Modified on"
msgstr "Última modificación en"

#. module: mass_mailing_event
#: field:event.registration.state,write_uid:0
msgid "Last Updated by"
msgstr "Última actualización por"

#. module: mass_mailing_event
#: field:event.registration.state,write_date:0
msgid "Last Updated on"
msgstr "Última actualización en"

#. module: mass_mailing_event
#: model:ir.model,name:mass_mailing_event.model_mail_mass_mailing
msgid "Mass Mailing"
msgstr "Envío masivo"

#. module: mass_mailing_event
#: model:ir.model,name:mass_mailing_event.model_mail_mass_mailing_contact
msgid "Mass Mailing Contact"
msgstr "Contacto"

#. module: mass_mailing_event
#: field:event.registration.state,name:0
msgid "Name"
msgstr "Nombre"

#. module: mass_mailing_event
#: model:ir.model,name:mass_mailing_event.model_res_partner
msgid "Partner"
msgstr "Empresa"

#. module: mass_mailing_event
#: view:mail.mass_mailing:mass_mailing_event.view_mail_mass_mailing_form
msgid "{'search_default_not_opt_out': 1, 'exclude_mass_mailing': active_id}"
msgstr "{'search_default_not_opt_out': 1, 'exclude_mass_mailing': active_id}"
8 changes: 8 additions & 0 deletions mass_mailing_event/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import event_registration_state
from . import mail_mass_mailing
from . import mail_mass_mailing_contact
from . import res_partner
from . import event_registration
20 changes: 20 additions & 0 deletions mass_mailing_event/models/event_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api
from .mail_mass_mailing import event_filtered_ids


class EventRegistration(models.Model):
_inherit = 'event.registration'

@api.model
def search_count(self, domain):
res = super(EventRegistration, self).search_count(domain)
mass_mailing_id = self.env.context.get('exclude_mass_mailing', False)
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
return res
12 changes: 12 additions & 0 deletions mass_mailing_event/models/event_registration_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields


class EventRegistrationState(models.Model):
_name = 'event.registration.state'

name = fields.Char(required=True)
code = fields.Char(required=True)
54 changes: 54 additions & 0 deletions mass_mailing_event/models/mail_mass_mailing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import copy
from openerp import models, fields, api


def event_filtered_ids(model, mass_mailing_id, domain, field='email'):
field = field or 'email'
domain = domain or []
exclude_emails = []
mass_mailing = model.env['mail.mass_mailing'].browse(mass_mailing_id)
if mass_mailing.event_id:
exclude = mass_mailing.exclude_event_state_ids.mapped('code')
reg_domain = False
registrations = model.env['event.registration']
if exclude:
reg_domain = [
('event_id', '=', mass_mailing.event_id.id),
('state', 'in', exclude)
]
if reg_domain:
registrations = registrations.search(reg_domain)
if registrations:
exclude_emails = registrations.mapped('email')
apply_domain = copy.deepcopy(domain)
if exclude_emails:
apply_domain.append((field, 'not in', exclude_emails))
rows = model.search(apply_domain)
return rows.ids


class MailMassMailing(models.Model):
_inherit = 'mail.mass_mailing'

def _default_exclude_event_state_ids(self):
return self.env['event.registration.state'].search([])

event_id = fields.Many2one(
string="Event related", comodel_name='event.event')
exclude_event_state_ids = fields.Many2many(
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)
if res_ids:
domain = [('id', 'in', res_ids)]
return event_filtered_ids(
self.env[mailing.mailing_model], mailing.id, domain,
field='email')
return res_ids
20 changes: 20 additions & 0 deletions mass_mailing_event/models/mail_mass_mailing_contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api
from .mail_mass_mailing import event_filtered_ids


class MailMassMailingContact(models.Model):
_inherit = 'mail.mass_mailing.contact'

@api.model
def search_count(self, domain):
res = super(MailMassMailingContact, self).search_count(domain)
mass_mailing_id = self.env.context.get('exclude_mass_mailing', False)
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
return res
20 changes: 20 additions & 0 deletions mass_mailing_event/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Antonio Espinosa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api
from .mail_mass_mailing import event_filtered_ids


class ResPartner(models.Model):
_inherit = 'res.partner'

@api.model
def search_count(self, domain):
res = super(ResPartner, self).search_count(domain)
mass_mailing_id = self.env.context.get('exclude_mass_mailing', False)
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
return res
2 changes: 2 additions & 0 deletions mass_mailing_event/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_event_registration_state_group_user","event_registration_state group_user","model_event_registration_state","base.group_user",1,0,0,0
Binary file added mass_mailing_event/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions mass_mailing_event/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_mass_mailing_event
Loading

0 comments on commit b9e0f57

Please sign in to comment.