diff --git a/mass_mailing_template_email/README.rst b/mass_mailing_template_email/README.rst new file mode 100644 index 00000000..392034c7 --- /dev/null +++ b/mass_mailing_template_email/README.rst @@ -0,0 +1,82 @@ +====================== +Mass Mailing Templates +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/10.0/mass_mailing_template_email + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-10-0/social-10-0-mass_mailing_template_email + :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/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Now you can add your own templates on your mass mailing campaigns. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Navigate to Mass Mailing -> Configuration -> Templates and add your templates +there. + +Navigate to Mass Mailing -> Mailings -> Mass Mailings and when you create a new +mass mailing, you will see the templates there. + +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 +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +George Daramouskas + +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_template_email/__init__.py b/mass_mailing_template_email/__init__.py new file mode 100644 index 00000000..a77aef9b --- /dev/null +++ b/mass_mailing_template_email/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, SUPERUSER_ID +from . import models diff --git a/mass_mailing_template_email/__manifest__.py b/mass_mailing_template_email/__manifest__.py new file mode 100644 index 00000000..1882da86 --- /dev/null +++ b/mass_mailing_template_email/__manifest__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Mass Mailing Templates", + "version": "10.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "social", + "summary": "Use email templates on mass mailing.", + "depends": [ + 'mail', + 'mass_mailing', + 'web', + ], + "data": [ + 'data/ir_ui_view.xml', + 'views/menus.xml', + 'views/editor_field_html.xml', + ], + "application": True, +} diff --git a/mass_mailing_template_email/data/ir_ui_view.xml b/mass_mailing_template_email/data/ir_ui_view.xml new file mode 100644 index 00000000..bed3e4da --- /dev/null +++ b/mass_mailing_template_email/data/ir_ui_view.xml @@ -0,0 +1,24 @@ + + + + + + Default Mass Mail Template + qweb + + extension + 1 + + + + ]]> + + + + diff --git a/mass_mailing_template_email/models/__init__.py b/mass_mailing_template_email/models/__init__.py new file mode 100644 index 00000000..391841b6 --- /dev/null +++ b/mass_mailing_template_email/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import mail_template diff --git a/mass_mailing_template_email/models/mail_template.py b/mass_mailing_template_email/models/mail_template.py new file mode 100644 index 00000000..aab67ec3 --- /dev/null +++ b/mass_mailing_template_email/models/mail_template.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class MailTemplate(models.Model): + """ In order for the mass email templates to be picked up by the js they + need to be formatted in a specific way, this is what we do here. + """ + _inherit = 'mail.template' + + view_id = fields.Many2one('ir.ui.view', ondelete='restrict', readonly=1) + + def _get_wrapped_body_html(self, body_html=None): + """ + This function is supposed to be used on the body_html of a newly + created template, it purpose is to wrap the body_html with an xpath + tag in order to be picked up by the snippet.editor widget. + """ + final = """" + """ + final += body_html if body_html else self.body_html + final += '' + return final + + @api.model + def create(self, vals): + """ + If a mail template for the mail_mass_mailing product is created, create + a ir_ui_view qweb record that will be used as a mass_mailing template. + """ + if vals.get('model_id') == self.env.ref( + 'mass_mailing.model_mail_mass_mailing').id: + arch = self._get_wrapped_body_html(vals.get('body_html')) + view_id = self.env['ir.ui.view'].create({ + 'arch': arch, + 'type': 'qweb', + 'inherit_id': self.env.ref( + 'mass_mailing_template_email.default_' + 'mass_mail_template').id, + }) + vals['view_id'] = view_id.id + return super(MailTemplate, self).create(vals) + + @api.multi + def write(self, vals): + """ + If the user tries to change the model of an already existing template, + we create the corresponding ir_ui_view qweb record (if not existing) + and we modify it's arch so that it is picked up correctly. + """ + model_id = vals.get('model_id') + if model_id and self.env['ir.model'].browse( + model_id).model == 'mail.mass_mailing': + body_html = vals.get('body_html') + body_html = body_html if body_html else self.body_html + new_body = self._get_wrapped_body_html(body_html) + if self.view_id: + self.view_id.write({'arch': new_body}) + else: + self.view_id.create({ + 'arch': new_body, + 'type': 'qweb', + 'inherit_id': self.env.ref( + 'mass_mailing_template_email.default_' + 'mass_mail_template').id + }) + # if they changed the model of a template that has as model the mass + # mailing model, go ahead and delete that view. + mass_mailing_model = self.env.ref( + 'mass_mailing.model_mail_mass_mailing') + if model_id and model_id != mass_mailing_model.id: + self.filtered( + lambda x: x.model_id.id == mass_mailing_model.id).mapped( + 'view_id').unlink() + return super(MailTemplate, self).write(vals) + + @api.multi + def unlink(self): + view_ids = self.mapped('view_id') + self.write({'view_id': None}) + view_ids.unlink() + return super(MailTemplate, self).unlink() diff --git a/mass_mailing_template_email/readme/CONTRIBUTORS.rst b/mass_mailing_template_email/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..4a1a72ba --- /dev/null +++ b/mass_mailing_template_email/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +George Daramouskas diff --git a/mass_mailing_template_email/readme/DESCRIPTION.rst b/mass_mailing_template_email/readme/DESCRIPTION.rst new file mode 100644 index 00000000..ebd91e1d --- /dev/null +++ b/mass_mailing_template_email/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Now you can add your own templates on your mass mailing campaigns. diff --git a/mass_mailing_template_email/readme/USAGE.rst b/mass_mailing_template_email/readme/USAGE.rst new file mode 100644 index 00000000..3b683735 --- /dev/null +++ b/mass_mailing_template_email/readme/USAGE.rst @@ -0,0 +1,5 @@ +Navigate to Mass Mailing -> Configuration -> Templates and add your templates +there. + +Navigate to Mass Mailing -> Mailings -> Mass Mailings and when you create a new +mass mailing, you will see the templates there. diff --git a/mass_mailing_template_email/static/description/icon.png b/mass_mailing_template_email/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mass_mailing_template_email/static/description/icon.png differ diff --git a/mass_mailing_template_email/static/description/index.html b/mass_mailing_template_email/static/description/index.html new file mode 100644 index 00000000..55010b5f --- /dev/null +++ b/mass_mailing_template_email/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +Mass Mailing Templates + + + +
+

Mass Mailing Templates

+ + +

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

+

Now you can add your own templates on your mass mailing campaigns.

+

Table of contents

+ +
+

Usage

+

Navigate to Mass Mailing -> Configuration -> Templates and add your templates +there.

+

Navigate to Mass Mailing -> Mailings -> Mass Mailings and when you create a new +mass mailing, you will see the templates there.

+
+
+

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

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+

George Daramouskas <gdaramouskas@therp.nl>

+
+
+

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_template_email/static/src/js/mass_mailing_template_email.js b/mass_mailing_template_email/static/src/js/mass_mailing_template_email.js new file mode 100644 index 00000000..32f81368 --- /dev/null +++ b/mass_mailing_template_email/static/src/js/mass_mailing_template_email.js @@ -0,0 +1,12 @@ +// Copyright 2019 Therp BV +// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +odoo.define('mass_mailing_template_email.editor', function (require){ + var snippets_editor = require('web_editor.snippet.editor'); + + snippets_editor.Class.include({ + compute_snippet_templates: function (html) { + this._super(html); + this.$('.o_mass_mailing_themes_upgrade').remove() + } + }) +}); diff --git a/mass_mailing_template_email/tests/__init__.py b/mass_mailing_template_email/tests/__init__.py new file mode 100644 index 00000000..ce9155b3 --- /dev/null +++ b/mass_mailing_template_email/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_mass_mailing_template_email diff --git a/mass_mailing_template_email/tests/test_mass_mailing_template_email.py b/mass_mailing_template_email/tests/test_mass_mailing_template_email.py new file mode 100644 index 00000000..3964f3bd --- /dev/null +++ b/mass_mailing_template_email/tests/test_mass_mailing_template_email.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openerp.tests.common import HttpCase + + +class TestMassMailingTemplateEmail(HttpCase): + + post_install = True + at_install = False + + def test_mass_mailing_template_email(self): + """ + Our process here is the following: + 1) Create a mail.mass_mailing record. Verify that no templates are + shown + 2) Create a template with the with the model mail.mass_mailing and + another one with res.users, verify that only the first one is + shown on the mail.mass_mailing record. + 3) Go ahead and send that mail.mass_mailing record. Check the body and + verify it contains the proper template body. + """ + mass_mailing = self.env['mail.mass_mailing'] + mail_template = self.env['mail.template'] + mass_mail = mass_mailing.create({'name': 'test'}) + self.assertFalse(mass_mail.body_html) + + template1 = mail_template.create({ + 'name': 'template1', + 'model_id': self.env.ref( + 'mass_mailing.model_mail_mass_mailing').id, + 'subject': 'test1', + 'body_html': '

test1

', + }) + template2 = mail_template.create({ + 'name': 'template2', + 'model_id': self.env.ref('mail.model_mail_mail').id, + 'subject': 'test', + 'body_html': '

test2

', + }) + self.url_open('/mass_mailing/snippets') diff --git a/mass_mailing_template_email/views/editor_field_html.xml b/mass_mailing_template_email/views/editor_field_html.xml new file mode 100644 index 00000000..0235bfdf --- /dev/null +++ b/mass_mailing_template_email/views/editor_field_html.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/mass_mailing_template_email/views/menus.xml b/mass_mailing_template_email/views/menus.xml new file mode 100644 index 00000000..3b005851 --- /dev/null +++ b/mass_mailing_template_email/views/menus.xml @@ -0,0 +1,25 @@ + + + + Templates + mail.template + form + form,tree + + + + + + + + +