Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] mass_mailing_resend #210

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions mass_mailing_resend/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.. 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

====================
Resend mass mailings
====================

A frequent need for users of mass mailings is to resend one mailing that has
already been sent in the past to new recipients that haven't received yet that
mail. But the problem is to know which are the applicable ones.

Odoo already includes a method in its mass mailing logic that avoids to resend
the same mail 2 times for one mass mailing, and for v9, there was a trick that
allows to modify the state of a mass mailing from kanban view, covering the
need.

But now on v10 both status bar in form view and dragging between states in
kanban are not allowed.

This module introduces a button to restart a mass mailing to draft state,
allowing you to reevaluate the sending domain or list for performing again
the mailing.

Usage
=====

* Go to *Mass mailing > Mailings > Mass Mailings*.
* Click on one record that is done or create a new one and send it.
* You will see a button called "Resend".
* If you click on it, mass mailing will be set to Draft again.

.. 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/10.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.

Known issues / Roadmap
======================

* Add an indicator / filter for knowing resent mailings.
* Include information on the number of new recipients to be sent on the
resending (through `get_remaining_recipients` method).


Credits
=======

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

* Tecnativa (https://www.tecnativa.com):
* Pedro M. Baeza <pedro.baeza@tecnativa.com>

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_resend/__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.html).

from . import models
21 changes: 21 additions & 0 deletions mass_mailing_resend/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Resend mass mailings",
"version": "10.0.1.0.0",
"category": "Marketing",
"website": "https://github.com/OCA/social",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"mass_mailing",
],
"data": [
"views/mass_mailing_views.xml",
],
}
38 changes: 38 additions & 0 deletions mass_mailing_resend/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mass_mailing_resend
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-11-22 10:42+0000\n"
"PO-Revision-Date: 2017-11-22 10:42+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_resend
#: model:ir.ui.view,arch_db:mass_mailing_resend.view_mail_mass_mailing_form
msgid "<i class=\"fa fa-info-circle\"/> New sending will be done only to not sent/new recipients. If you want to resend again the mass mailing to already sent recipients, click on <b>Emails Sent</b> smart-button for removing the existing record(s)."
msgstr "<i class=\"fa fa-info-circle\"/> El nuevo envío se realizará solo a los destinatarios no enviados/nuevos. Si quiere reenviar otra vez el correo masivo a destinatarios ya enviados, pulse en el botón <b>Correos enviados</b> para eliminar el/los registro/s existentes."

#. module: mass_mailing_resend
#: model:ir.model,name:mass_mailing_resend.model_mail_mass_mailing
msgid "Mass Mailing"
msgstr "Correo masivo"

#. module: mass_mailing_resend
#: model:ir.ui.view,arch_db:mass_mailing_resend.view_mail_mass_mailing_form
msgid "Resend"
msgstr "Reenviar"

#. module: mass_mailing_resend
#: code:addons/mass_mailing_resend/models/mass_mailing.py:16
#, python-format
msgid "You can't resend a mass mailing that is being sent or in draft state."
msgstr "No puede reenviar un correo masivo que está siendo enviado en estado borrador."

4 changes: 4 additions & 0 deletions mass_mailing_resend/models/__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.html).

from . import mass_mailing
19 changes: 19 additions & 0 deletions mass_mailing_resend/models/mass_mailing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import _, exceptions, models


class MailMassMailingList(models.Model):
_inherit = "mail.mass_mailing"

def button_draft(self):
"""Return to draft state for resending the mass mailing."""
if any(self.mapped(lambda x: x.state != 'done')):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if self.filtered(...):, or use a normal for loop, which is more performant since it would stop at 1st match.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, as the list is going to be very short, I prefer this formula to avoid one cyclomatic level more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In such case, use if self.filtered(...)

raise exceptions.UserError(
_("You can't resend a mass mailing that is being sent or in "
"draft state.")
)
self.write({'state': 'draft'})
Binary file added mass_mailing_resend/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.
84 changes: 84 additions & 0 deletions mass_mailing_resend/static/description/icon.svg
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_resend/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.html).

from . import test_mass_mailing_resend
36 changes: 36 additions & 0 deletions mass_mailing_resend/tests/test_mass_mailing_resend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests import common
from odoo import exceptions


class TestMassMailingResend(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestMassMailingResend, cls).setUpClass()
cls.list = cls.env['mail.mass_mailing.list'].create({
'name': 'Test list',
})
cls.contact1 = cls.env['mail.mass_mailing.contact'].create({
'name': 'Contact 1',
'email': 'email1@test.com',
})
cls.mass_mailing = cls.env['mail.mass_mailing'].create({
'name': 'Test mass mailing',
'email_from': 'test@example.org',
'mailing_model': 'mail.mass_mailing.contact',
'contact_list_ids': [(6, 0, cls.list.ids)],
'reply_to_mode': 'thread',
})

def test_resend_error(self):
with self.assertRaises(exceptions.UserError):
self.mass_mailing.button_draft()

def test_resend(self):
self.mass_mailing.state = 'done' # Force state
self.assertEqual(self.mass_mailing.state, 'done')
self.mass_mailing.button_draft()
self.assertEqual(self.mass_mailing.state, 'draft')
28 changes: 28 additions & 0 deletions mass_mailing_resend/views/mass_mailing_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record model="ir.ui.view" id="view_mail_mass_mailing_form">
<field name="model">mail.mass_mailing</field>
<field name="inherit_id" ref="mass_mailing.view_mail_mass_mailing_form"/>
<field name="arch" type="xml">
<field name="state" position="before">
<button string="Resend"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think "resend" is a bit misleading? Because you are not actually "resending" it, just setting back as draft. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A helpwould also be useful here noting that the mail will only be sent to new recipients.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer resend word that is more user friendly, because setting back to draft is for resending purpose, although I'm going to add a text when clicked explaining about the new recipients.

states="done"
name="button_draft"
type="object"
/>
</field>
<header position="after">
<div class="alert alert-warning oe_text_center" attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('sent', '=', '0')]}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the flow: shouldn't this be more like:

{'invisible': ['|', ('state', '=', 'done'), ('state', '!=', 'done'), ('sent', '=', '0')]}

So it's only visible when a mailing is reset to draft and it has sent mails. Otherwise it's visible at the first composition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's correct as it's now: it's only visible when on draft and sent > 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it when draft or sent = 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get you. Please re-read my comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yeah. I got it wrong because the second condition doesn't seem to be working fine. When you create a new draft mailing the bubble is visible (maybe is False until the field is computed by the first time?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it was more subtle than that 😄 The quotes in ('sent', '=', '0') are avoiding proper evaluation. So, this should work:

{'invisible': ['|', ('state', '!=', 'draft'), ('sent', '=', 0)]}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agh...

<p>
<i class="fa fa-info-circle"/> New sending will be done only to not sent/new recipients. If you want to resend again the mass mailing to already sent recipients, click on <b>Emails Sent</b> smart-button for removing the existing record(s).
</p>
</div>
</header>
<div name="button_box" position="attributes">
<attribute name="attrs">{'invisible': [('sent', '=', 0)]}</attribute>
</div>
</field>
</record>

</odoo>