diff --git a/mass_mailing_custom_unsubscribe_event/README.rst b/mass_mailing_custom_unsubscribe_event/README.rst new file mode 100644 index 000000000..64fac68d2 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/README.rst @@ -0,0 +1,92 @@ +============================================= +Allow to unsubscribe discretely from an event +============================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/13.0/mass_mailing_custom_unsubscribe_event + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-13-0/social-13-0-mass_mailing_custom_unsubscribe_event + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon extends the unsubscription process for allowing to unsubscribe +only for an event. + +Standard process includes the mail in the general blacklist instead, which +can be very unconvenient. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Go to *Email Marketing > Mailings > Create*. +#. Select "Event Registration" in *Recipients* field. +#. Edit your mass mailing at wish, but remember to add a snippet from + *Footers*, so people have an *Unsubscribe* link. +#. Send it. +#. If somebody gets unsubscribed, it will get unsubscribed only for that + event, but including that mail in other event, the registree will still + receive mailings. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Pedro M. Baeza + * João Marques + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mass_mailing_custom_unsubscribe_event/__init__.py b/mass_mailing_custom_unsubscribe_event/__init__.py new file mode 100644 index 000000000..69f7babdf --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mass_mailing_custom_unsubscribe_event/__manifest__.py b/mass_mailing_custom_unsubscribe_event/__manifest__.py new file mode 100644 index 000000000..3543c8f34 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# Copyright 2020 Tecnativa - João Marques +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Allow to unsubscribe discretely from an event", + "category": "Marketing", + "version": "15.0.1.0.0", + "depends": ["event", "mass_mailing_custom_unsubscribe"], + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "data": ["views/event_registration_views.xml"], + "assets": { + "web.assets_tests": [ + "/mass_mailing_custom_unsubscribe_event/static/src/js/tour.esm.js" + ] + }, + "license": "AGPL-3", + "installable": True, + "auto_install": True, +} diff --git a/mass_mailing_custom_unsubscribe_event/i18n/mass_mailing_custom_unsubscribe_event.pot b/mass_mailing_custom_unsubscribe_event/i18n/mass_mailing_custom_unsubscribe_event.pot new file mode 100644 index 000000000..e0bbb2f1a --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/i18n/mass_mailing_custom_unsubscribe_event.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mass_mailing_custom_unsubscribe_event +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \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_custom_unsubscribe_event +#: model:ir.model,name:mass_mailing_custom_unsubscribe_event.model_event_registration +msgid "Event Registration" +msgstr "" + +#. module: mass_mailing_custom_unsubscribe_event +#: model:ir.model.fields,help:mass_mailing_custom_unsubscribe_event.field_event_registration__opt_out +msgid "" +"If opt-out is checked, this registree has refused to receive emails for mass" +" mailing and marketing campaign." +msgstr "" + +#. module: mass_mailing_custom_unsubscribe_event +#: model:ir.model.fields,field_description:mass_mailing_custom_unsubscribe_event.field_event_registration__opt_out +msgid "Opt-Out" +msgstr "" diff --git a/mass_mailing_custom_unsubscribe_event/models/__init__.py b/mass_mailing_custom_unsubscribe_event/models/__init__.py new file mode 100644 index 000000000..950934286 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import event_registration diff --git a/mass_mailing_custom_unsubscribe_event/models/event_registration.py b/mass_mailing_custom_unsubscribe_event/models/event_registration.py new file mode 100644 index 000000000..80afcd8ff --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/models/event_registration.py @@ -0,0 +1,15 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class EventRegistration(models.Model): + _inherit = "event.registration" + + opt_out = fields.Boolean( + string="Opt-Out", + help="If opt-out is checked, this registree has refused to receive " + "emails for mass mailing and marketing campaign.", + ) + # No need of email field, as it already exists diff --git a/mass_mailing_custom_unsubscribe_event/readme/CONTRIBUTORS.rst b/mass_mailing_custom_unsubscribe_event/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..769b9f27a --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Pedro M. Baeza + * João Marques diff --git a/mass_mailing_custom_unsubscribe_event/readme/DESCRIPTION.rst b/mass_mailing_custom_unsubscribe_event/readme/DESCRIPTION.rst new file mode 100644 index 000000000..307efe31c --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This addon extends the unsubscription process for allowing to unsubscribe +only for an event. + +Standard process includes the mail in the general blacklist instead, which +can be very unconvenient. diff --git a/mass_mailing_custom_unsubscribe_event/readme/USAGE.rst b/mass_mailing_custom_unsubscribe_event/readme/USAGE.rst new file mode 100644 index 000000000..552d294ec --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/readme/USAGE.rst @@ -0,0 +1,8 @@ +#. Go to *Email Marketing > Mailings > Create*. +#. Select "Event Registration" in *Recipients* field. +#. Edit your mass mailing at wish, but remember to add a snippet from + *Footers*, so people have an *Unsubscribe* link. +#. Send it. +#. If somebody gets unsubscribed, it will get unsubscribed only for that + event, but including that mail in other event, the registree will still + receive mailings. diff --git a/mass_mailing_custom_unsubscribe_event/static/description/icon.png b/mass_mailing_custom_unsubscribe_event/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mass_mailing_custom_unsubscribe_event/static/description/icon.png differ diff --git a/mass_mailing_custom_unsubscribe_event/static/description/index.html b/mass_mailing_custom_unsubscribe_event/static/description/index.html new file mode 100644 index 000000000..221a55237 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Allow to unsubscribe discretely from an event + + + +
+

Allow to unsubscribe discretely from an event

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

This addon extends the unsubscription process for allowing to unsubscribe +only for an event.

+

Standard process includes the mail in the general blacklist instead, which +can be very unconvenient.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Email Marketing > Mailings > Create.
  2. +
  3. Select “Event Registration” in Recipients field.
  4. +
  5. Edit your mass mailing at wish, but remember to add a snippet from +Footers, so people have an Unsubscribe link.
  6. +
  7. Send it.
  8. +
  9. If somebody gets unsubscribed, it will get unsubscribed only for that +event, but including that mail in other event, the registree will still +receive mailings.
  10. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Pedro M. Baeza
    • +
    • João Marques
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mass_mailing_custom_unsubscribe_event/static/src/js/tour.esm.js b/mass_mailing_custom_unsubscribe_event/static/src/js/tour.esm.js new file mode 100644 index 000000000..0ded979e6 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/static/src/js/tour.esm.js @@ -0,0 +1,36 @@ +/** @odoo-module **/ + +/* Copyright 2020 Tecnativa - João Marques + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +import tour from "web_tour.tour"; + +tour.register( + "mass_mailing_custom_unsubscribe_event_tour", + { + test: true, + }, + [ + { + content: "Choose other reason", + trigger: ".radio:contains('Other reason') :radio:not(:checked)", + extra_trigger: "#reason_form #custom_div_feedback", + }, + { + content: "Switch to not interested reason", + trigger: '.radio:contains("I\'m not interested") :radio:not(:checked)', + extra_trigger: "[name='details']:propRequired", + }, + { + content: "Unsubscribe", + trigger: "#reason_form button:submit", + extra_trigger: "body:not(:has([name='details']:propRequired))", + }, + { + content: "Successfully unsubscribed", + trigger: + "body:not(:has(#reason_form)) #subscription_info " + + ":contains('successfully unsubscribed')", + }, + ] +); diff --git a/mass_mailing_custom_unsubscribe_event/tests/__init__.py b/mass_mailing_custom_unsubscribe_event/tests/__init__.py new file mode 100644 index 000000000..d88d3b1a1 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Tecnativa - João Marques +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_ui diff --git a/mass_mailing_custom_unsubscribe_event/tests/test_ui.py b/mass_mailing_custom_unsubscribe_event/tests/test_ui.py new file mode 100644 index 000000000..55c913d10 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/tests/test_ui.py @@ -0,0 +1,143 @@ +# Copyright 2020 Tecnativa - João Marques +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from unittest import mock + +from werkzeug import urls + +from odoo.tests.common import HttpCase, tagged + + +@tagged("post_install", "-at_install") +class UICase(HttpCase): + def extract_url(self, mail, *args, **kwargs): + url = mail.mailing_id._get_unsubscribe_url(self.email, mail.res_id) + self.assertTrue(urls.url_parse(url).decode_query().get("token")) + self.assertTrue(url.startswith(self.domain)) + self.url = url.replace(self.domain, "", 1) + return True + + def setUp(self): + super().setUp() + self.email = "test.contact@example.com" + self.mail_postprocess_patch = mock.patch( + "odoo.addons.mass_mailing.models.mail_mail.MailMail." + "_postprocess_sent_message", + autospec=True, + side_effect=self.extract_url, + ) + self.domain = self.env["ir.config_parameter"].get_param("web.base.url") + + self.partner = self.env["res.partner"].create( + {"name": "Demo Partner <%s>" % self.email, "email": self.email} + ) + self.event_1 = self.env["event.event"].create( + { + "name": "test_event_2", + "event_type_id": 1, + "date_end": "2012-01-01 19:05:15", + "date_begin": "2012-01-01 18:05:15", + } + ) + self.event_2 = self.env["event.event"].create( + { + "name": "test_event_2", + "event_type_id": 1, + "date_end": "2012-01-01 19:05:15", + "date_begin": "2012-01-01 18:05:15", + } + ) + self.event_registration_1 = self.env["event.registration"].create( + { + "name": "test_registration_1", + "event_id": self.event_1.id, + "email": self.email, + "partner_id": self.partner.id, + } + ) + self.event_registration_2 = self.env["event.registration"].create( + { + "name": "test_registration_2", + "event_id": self.event_2.id, + "email": self.email, + "partner_id": self.partner.id, + } + ) + self.mailing_1 = self.env["mailing.mailing"].create( + { + "name": "test_mailing_1", + "mailing_model_id": self.env.ref("event.model_event_registration").id, + "mailing_domain": "[['id','=',%s]]" % self.event_registration_1.id, + "reply_to_mode": "update", + "subject": "Test 1", + } + ) + self.mailing_1.body_html = """ + + """ + self.mailing_2 = self.env["mailing.mailing"].create( + { + "name": "test_mailing_2", + "mailing_model_id": self.env.ref("event.model_event_registration").id, + "mailing_domain": "[['id','=',%s]]" % self.event_registration_2.id, + "reply_to_mode": "update", + "subject": "Test 2", + } + ) + self.mailing_2.body_html = """ + + """ + + def tearDown(self): + del ( + self.email, + self.event_1, + self.event_2, + self.event_registration_1, + self.event_registration_2, + self.mailing_1, + self.mailing_2, + self.partner, + self.url, + ) + super(UICase, self).tearDown() + + def test_unsubscription_event_1(self): + """Test a mass mailing contact that wants to unsubscribe.""" + # Extract the unsubscription link from the message body + with self.mail_postprocess_patch: + self.mailing_1.action_send_mail() + tour = "mass_mailing_custom_unsubscribe_event_tour" + self.start_tour(url_path=self.url, tour_name=tour, login="demo") + # Check results from running tour + # User should be opted out from event 1 mailing list + self.assertTrue(self.event_registration_1.opt_out) + # User should not be opted out from event 2 mailing list + self.assertFalse(self.event_registration_2.opt_out) + reason_xid = "mass_mailing_custom_unsubscribe.reason_not_interested" + unsubscriptions = self.env["mail.unsubscription"].search( + [ + ("action", "=", "unsubscription"), + ("mass_mailing_id", "=", self.mailing_1.id), + ("email", "=", self.email), + ( + "unsubscriber_id", + "=", + "event.registration,%d" % self.event_registration_1.id, + ), + ("details", "=", False), + ("reason_id", "=", self.env.ref(reason_xid).id), + ] + ) + # Unsubscription record must exist + self.assertEqual(1, len(unsubscriptions)) + self.mailing_2.action_send_mail() + # Mail to user must have been sent + self.assertEqual(1, self.mailing_2.sent) diff --git a/mass_mailing_custom_unsubscribe_event/views/event_registration_views.xml b/mass_mailing_custom_unsubscribe_event/views/event_registration_views.xml new file mode 100644 index 000000000..a637637e0 --- /dev/null +++ b/mass_mailing_custom_unsubscribe_event/views/event_registration_views.xml @@ -0,0 +1,17 @@ + + + + + + event.registration.form - Add opt_out + event.registration + + + + + + + + + diff --git a/setup/mass_mailing_custom_unsubscribe_event/odoo/addons/mass_mailing_custom_unsubscribe_event b/setup/mass_mailing_custom_unsubscribe_event/odoo/addons/mass_mailing_custom_unsubscribe_event new file mode 120000 index 000000000..24aa35046 --- /dev/null +++ b/setup/mass_mailing_custom_unsubscribe_event/odoo/addons/mass_mailing_custom_unsubscribe_event @@ -0,0 +1 @@ +../../../../mass_mailing_custom_unsubscribe_event \ No newline at end of file diff --git a/setup/mass_mailing_custom_unsubscribe_event/setup.py b/setup/mass_mailing_custom_unsubscribe_event/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mass_mailing_custom_unsubscribe_event/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)