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..eefa8fa52
--- /dev/null
+++ b/mass_mailing_custom_unsubscribe_event/demo/assets.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
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/src/js/tour.js b/mass_mailing_custom_unsubscribe_event/static/src/js/tour.js
new file mode 100644
index 000000000..c85adde1d
--- /dev/null
+++ b/mass_mailing_custom_unsubscribe_event/static/src/js/tour.js
@@ -0,0 +1,47 @@
+/* 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)