diff --git a/mass_mailing_custom_unsubscribe_event/README.rst b/mass_mailing_custom_unsubscribe_event/README.rst
index 10ecb4314..64fac68d2 100644
--- a/mass_mailing_custom_unsubscribe_event/README.rst
+++ b/mass_mailing_custom_unsubscribe_event/README.rst
@@ -14,13 +14,13 @@ Allow to unsubscribe discretely from an event
: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/12.0/mass_mailing_custom_unsubscribe_event
+ :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-12-0/social-12-0-mass_mailing_custom_unsubscribe_event
+ :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/12.0
+ :target: https://runbot.odoo-community.org/runbot/205/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -54,7 +54,7 @@ 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -72,6 +72,7 @@ Contributors
* `Tecnativa `_:
* Pedro M. Baeza
+ * João Marques
Maintainers
~~~~~~~~~~~
@@ -86,6 +87,6 @@ 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.
+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/__manifest__.py b/mass_mailing_custom_unsubscribe_event/__manifest__.py
index a05202809..c36e0dd93 100644
--- a/mass_mailing_custom_unsubscribe_event/__manifest__.py
+++ b/mass_mailing_custom_unsubscribe_event/__manifest__.py
@@ -1,13 +1,15 @@
# 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": "12.0.1.0.1",
+ "version": "13.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"],
+ "demo": ["demo/assets.xml"],
"license": "AGPL-3",
"installable": True,
"auto_install": True,
diff --git a/mass_mailing_custom_unsubscribe_event/demo/assets.xml b/mass_mailing_custom_unsubscribe_event/demo/assets.xml
new file mode 100644
index 000000000..c52ea4c61
--- /dev/null
+++ b/mass_mailing_custom_unsubscribe_event/demo/assets.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
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
index 829e503c2..e0bbb2f1a 100644
--- 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
@@ -1,12 +1,12 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
-# * mass_mailing_custom_unsubscribe_event
+# * mass_mailing_custom_unsubscribe_event
#
msgid ""
msgstr ""
-"Project-Id-Version: Odoo Server 12.0\n"
+"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
-"Last-Translator: <>\n"
+"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -20,11 +20,12 @@ 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."
+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/readme/CONTRIBUTORS.rst b/mass_mailing_custom_unsubscribe_event/readme/CONTRIBUTORS.rst
index 2d4d7a884..769b9f27a 100644
--- a/mass_mailing_custom_unsubscribe_event/readme/CONTRIBUTORS.rst
+++ b/mass_mailing_custom_unsubscribe_event/readme/CONTRIBUTORS.rst
@@ -1,3 +1,4 @@
* `Tecnativa `_:
* Pedro M. Baeza
+ * João Marques
diff --git a/mass_mailing_custom_unsubscribe_event/static/description/index.html b/mass_mailing_custom_unsubscribe_event/static/description/index.html
index 66899cbe1..221a55237 100644
--- a/mass_mailing_custom_unsubscribe_event/static/description/index.html
+++ b/mass_mailing_custom_unsubscribe_event/static/description/index.html
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

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
@@ -403,7 +403,7 @@ receive mailings.
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.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -419,6 +419,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
@@ -430,7 +431,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
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.
+
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.js b/mass_mailing_custom_unsubscribe_event/static/src/js/tour.js
new file mode 100644
index 000000000..3149fa9b6
--- /dev/null
+++ b/mass_mailing_custom_unsubscribe_event/static/src/js/tour.js
@@ -0,0 +1,45 @@
+/* Copyright 2020 Tecnativa - João Marques
+ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
+odoo.define("mass_mailing_custom_unsubscribe_event.tour", function(require) {
+ "use strict";
+ var base = require("web_editor.base");
+ var tour = require("web_tour.tour");
+
+ // Allow to know if an element is required
+ $.extend($.expr[":"], {
+ propRequired: function(element) {
+ return $(element).prop("required");
+ },
+ });
+
+ tour.register(
+ "mass_mailing_custom_unsubscribe_event_tour",
+ {
+ test: true,
+ wait_for: base.ready(),
+ },
+ [
+ {
+ 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..8b62418bd
--- /dev/null
+++ b/mass_mailing_custom_unsubscribe_event/tests/test_ui.py
@@ -0,0 +1,154 @@
+# Copyright 2020 Tecnativa - João Marques
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+import mock
+from werkzeug import urls
+
+from odoo.tests.common import HttpCase
+
+
+class UICase(HttpCase):
+ def extract_url(self, mail, *args, **kwargs):
+ url = mail._get_unsubscribe_url(self.email)
+ 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(UICase, self).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": "email",
+ "subject": "Test 1",
+ }
+ )
+ self.mailing_1._onchange_model_and_list()
+ # HACK https://github.com/odoo/odoo/pull/14429
+ 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": "email",
+ "subject": "Test 2",
+ }
+ )
+ self.mailing_2._onchange_model_and_list()
+ # HACK https://github.com/odoo/odoo/pull/14429
+ 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
index e754a1d33..a637637e0 100644
--- a/mass_mailing_custom_unsubscribe_event/views/event_registration_views.xml
+++ b/mass_mailing_custom_unsubscribe_event/views/event_registration_views.xml
@@ -1,13 +1,12 @@
-
+
-
event.registration.form - Add opt_out
event.registration
-
+