diff --git a/mail_layout_preview/README.rst b/mail_layout_preview/README.rst new file mode 100644 index 000000000..8847b234b --- /dev/null +++ b/mail_layout_preview/README.rst @@ -0,0 +1,113 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============ +Mail Preview +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:abc38a06b36f72f669b1eb326e3d9b665154a03c56625f84f3c629059ec78bb4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/19.0/mail_layout_preview + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-19-0/mail-19-0-mail_layout_preview + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +The purpose of this module is to help development of email templates +allowing to render the full layout preview of each of them. + +Odoo already allows you do preview emails but they are wrapped into Odoo +backend theme. + +NOTE: to make work properly your emails it's strongly recommended to use +mail_inline_css to include all styles in the body of the email. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Go to a template and click on the preview button +- Select desired params and click on "Full layout preview" link +- You'll get to the preview + +As a developer, you can see a list of all templates for a model by going +to: + + /email-preview/$model.name + +You'll get a list of all the templates. Follow the instructions there on +how to use the links. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Simone Orsi +- Phuc Tran Thanh +- Son Ho +- Khoi (Kien Kim) + +Other credits +------------- + +The development and migration of this module from 15.0 to 16.0 and from +17.0 to 18.0 has been financially supported by: + +- Camptocamp + +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/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_layout_preview/__init__.py b/mail_layout_preview/__init__.py new file mode 100644 index 000000000..9b7fdc981 --- /dev/null +++ b/mail_layout_preview/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import wizard diff --git a/mail_layout_preview/__manifest__.py b/mail_layout_preview/__manifest__.py new file mode 100644 index 000000000..d404ff2d8 --- /dev/null +++ b/mail_layout_preview/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Mail Preview", + "summary": """ + Preview email templates in the browser""", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "Camptocamp,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/mail", + "depends": ["mail"], + "data": ["templates/email_preview.xml", "wizard/email_template_preview.xml"], + "development_status": "Beta", +} diff --git a/mail_layout_preview/controllers/__init__.py b/mail_layout_preview/controllers/__init__.py new file mode 100644 index 000000000..07dab3c8e --- /dev/null +++ b/mail_layout_preview/controllers/__init__.py @@ -0,0 +1 @@ +from . import layout_preview diff --git a/mail_layout_preview/controllers/layout_preview.py b/mail_layout_preview/controllers/layout_preview.py new file mode 100644 index 000000000..1ab787f1b --- /dev/null +++ b/mail_layout_preview/controllers/layout_preview.py @@ -0,0 +1,47 @@ +# Copyright 2020 Simone Orsi - Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import http +from odoo.fields import Domain +from odoo.http import request + + +class Preview(http.Controller): + _list_template = "mail_layout_preview.email_templates_list" + + @http.route( + ["/email-preview/"], type="http", auth="user", website=True + ) + def template_list(self, model, **kw): + env = request.env + templates = env["mail.template"].search(Domain("model_id.model", "=", model)) + xids = templates.get_external_id() + return request.render( + self._list_template, {"model": model, "templates": templates, "xids": xids} + ) + + @http.route( + ["/email-preview///"], + type="http", + auth="user", + website=True, + ) + def preview(self, model, templ_id, rec_id, **kw): + """Render an email template to verify look and feel. + + Provide model, record id and an email template to render. + + Example for event registration email: + + /email-preview/event.registration/event.event_subscription/5 + """ + env = request.env + record = env[model].browse(rec_id) + if templ_id.isdigit(): + # got an ID + template = env["mail.template"].browse(int(templ_id)) + else: + # got a XID + template = env.ref(templ_id.strip()) + result = template._generate_template([record.id], ["body_html"]) + return request.make_response(result[record.id]["body_html"]) diff --git a/mail_layout_preview/i18n/es.po b/mail_layout_preview/i18n/es.po new file mode 100644 index 000000000..70a3cf300 --- /dev/null +++ b/mail_layout_preview/i18n/es.po @@ -0,0 +1,96 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_layout_preview +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-09 17:37+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Link:" +msgstr "Enlace:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Name:" +msgstr "Nombre:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "XMLID:" +msgstr "XMLID:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Copy the link" +msgstr "Copiar el enlace" + +#. module: mail_layout_preview +#: model:ir.model,name:mail_layout_preview.model_mail_template_preview +msgid "Email Template Preview" +msgstr "Previsualización plantilla Email" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Email templates for:" +msgstr "Plantillas de correo electrónico para:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Find your template" +msgstr "Encuentre su plantilla" + +#. module: mail_layout_preview +#: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview__layout_preview_url +msgid "Full layout preview" +msgstr "Vista previa completa del diseño" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Here you find all the template for the given model." +msgstr "Aquí encontrará todas las plantillas del modelo en cuestión." + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Load it" +msgstr "Cárgalo" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "No template found." +msgstr "No se ha encontrado ninguna plantilla." + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "" +"Paste into the address bar and change the record ID (the last value in the " +"URL).\n" +"
If you don't know the ID of the record, just browse to " +"the record via odoo interface and check its ID in the address bar `#id=XXX`." +msgstr "" +"Pegue en la barra de direcciones y cambie el ID del registro (el último " +"valor en la URL).\n" +"
Si no conoce el ID del registro, simplemente busque el " +"registro a través de la interfaz de odoo y verifique su ID en la barra de " +"direcciones `#id=XXX`." + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Preview" +msgstr "Previsualización" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "View in backend" +msgstr "Ver en el servidor" diff --git a/mail_layout_preview/i18n/it.po b/mail_layout_preview/i18n/it.po new file mode 100644 index 000000000..5fd5fa850 --- /dev/null +++ b/mail_layout_preview/i18n/it.po @@ -0,0 +1,96 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_layout_preview +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-07 12:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Link:" +msgstr "Collegamento:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Name:" +msgstr "Nome:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "XMLID:" +msgstr "XMLID:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Copy the link" +msgstr "Copia collegamento" + +#. module: mail_layout_preview +#: model:ir.model,name:mail_layout_preview.model_mail_template_preview +msgid "Email Template Preview" +msgstr "Anteprima modello e-mail" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Email templates for:" +msgstr "Modello e-mail per:" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Find your template" +msgstr "Trova il tuo modello" + +#. module: mail_layout_preview +#: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview__layout_preview_url +msgid "Full layout preview" +msgstr "Anteprima impaginazione piena" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Here you find all the template for the given model." +msgstr "Qui si trovano tutti i modelli per il tipo dato." + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Load it" +msgstr "Caricalo" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "No template found." +msgstr "Nessun modello trovato." + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "" +"Paste into the address bar and change the record ID (the last value in the " +"URL).\n" +"
If you don't know the ID of the record, just browse to " +"the record via odoo interface and check its ID in the address bar `#id=XXX`." +msgstr "" +"Incollare nella barra indirizzo e modificare l'ID record (l'ultimo valore " +"nell'URL).\n" +"
Se non si conosce l'ID del record, navigare fino al " +"record con l'interfaccia Odoo e controllare l'ID nella " +"barraindirizzo`#id=XXX`." + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Preview" +msgstr "Anteprima" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "View in backend" +msgstr "Vedi nel backend" diff --git a/mail_layout_preview/i18n/mail_layout_preview.pot b/mail_layout_preview/i18n/mail_layout_preview.pot new file mode 100644 index 000000000..bcf367413 --- /dev/null +++ b/mail_layout_preview/i18n/mail_layout_preview.pot @@ -0,0 +1,86 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_layout_preview +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Link:" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Name:" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "XMLID:" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Copy the link" +msgstr "" + +#. module: mail_layout_preview +#: model:ir.model,name:mail_layout_preview.model_mail_template_preview +msgid "Email Template Preview" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Email templates for:" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Find your template" +msgstr "" + +#. module: mail_layout_preview +#: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview__layout_preview_url +msgid "Full layout preview" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Here you find all the template for the given model." +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Load it" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "No template found." +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "" +"Paste into the address bar and change the record ID (the last value in the URL).\n" +"
If you don't know the ID of the record, just browse to the record via odoo interface and check its ID in the address bar `#id=XXX`." +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "Preview" +msgstr "" + +#. module: mail_layout_preview +#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list +msgid "View in backend" +msgstr "" diff --git a/mail_layout_preview/pyproject.toml b/mail_layout_preview/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_layout_preview/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_layout_preview/readme/CONTRIBUTORS.md b/mail_layout_preview/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..d639663a4 --- /dev/null +++ b/mail_layout_preview/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Simone Orsi \<\> +- Phuc Tran Thanh \<\> +- Son Ho \<\> +- Khoi (Kien Kim) \<\> diff --git a/mail_layout_preview/readme/CREDITS.md b/mail_layout_preview/readme/CREDITS.md new file mode 100644 index 000000000..fea81e1fa --- /dev/null +++ b/mail_layout_preview/readme/CREDITS.md @@ -0,0 +1,4 @@ +The development and migration of this module from 15.0 to 16.0 and +from 17.0 to 18.0 has been financially supported by: + +- Camptocamp diff --git a/mail_layout_preview/readme/DESCRIPTION.md b/mail_layout_preview/readme/DESCRIPTION.md new file mode 100644 index 000000000..bf904b457 --- /dev/null +++ b/mail_layout_preview/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +The purpose of this module is to help development of email templates +allowing to render the full layout preview of each of them. + +Odoo already allows you do preview emails but they are wrapped into Odoo +backend theme. + +NOTE: to make work properly your emails it's strongly recommended to use +mail_inline_css to include all styles in the body of the email. diff --git a/mail_layout_preview/readme/USAGE.md b/mail_layout_preview/readme/USAGE.md new file mode 100644 index 000000000..1354d267e --- /dev/null +++ b/mail_layout_preview/readme/USAGE.md @@ -0,0 +1,11 @@ +- Go to a template and click on the preview button +- Select desired params and click on "Full layout preview" link +- You'll get to the preview + +As a developer, you can see a list of all templates for a model by going +to: + +> /email-preview/\$model.name + +You'll get a list of all the templates. Follow the instructions there on +how to use the links. diff --git a/mail_layout_preview/static/description/icon.png b/mail_layout_preview/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_layout_preview/static/description/icon.png differ diff --git a/mail_layout_preview/static/description/index.html b/mail_layout_preview/static/description/index.html new file mode 100644 index 000000000..cbfeb84ce --- /dev/null +++ b/mail_layout_preview/static/description/index.html @@ -0,0 +1,461 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mail Preview

+ +

Beta License: AGPL-3 OCA/mail Translate me on Weblate Try me on Runboat

+

The purpose of this module is to help development of email templates +allowing to render the full layout preview of each of them.

+

Odoo already allows you do preview emails but they are wrapped into Odoo +backend theme.

+

NOTE: to make work properly your emails it’s strongly recommended to use +mail_inline_css to include all styles in the body of the email.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to a template and click on the preview button
  • +
  • Select desired params and click on “Full layout preview” link
  • +
  • You’ll get to the preview
  • +
+

As a developer, you can see a list of all templates for a model by going +to:

+
+/email-preview/$model.name
+

You’ll get a list of all the templates. Follow the instructions there on +how to use the links.

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The development and migration of this module from 15.0 to 16.0 and from +17.0 to 18.0 has been financially supported by:

+
    +
  • Camptocamp
  • +
+
+
+

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/mail project on GitHub.

+

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

+
+
+
+
+ + diff --git a/mail_layout_preview/templates/email_preview.xml b/mail_layout_preview/templates/email_preview.xml new file mode 100644 index 000000000..3e89dc1b8 --- /dev/null +++ b/mail_layout_preview/templates/email_preview.xml @@ -0,0 +1,57 @@ + + + + diff --git a/mail_layout_preview/tests/__init__.py b/mail_layout_preview/tests/__init__.py new file mode 100644 index 000000000..365703cfa --- /dev/null +++ b/mail_layout_preview/tests/__init__.py @@ -0,0 +1 @@ +from . import test_layout_preview diff --git a/mail_layout_preview/tests/test_layout_preview.py b/mail_layout_preview/tests/test_layout_preview.py new file mode 100644 index 000000000..2003374fe --- /dev/null +++ b/mail_layout_preview/tests/test_layout_preview.py @@ -0,0 +1,82 @@ +# Copyright 2020 Camptocamp SA (http://www.camptocamp.com) +# Simone Orsi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from lxml import etree + +from odoo import tools +from odoo.fields import Domain +from odoo.tests.common import HttpCase, TransactionCase, tagged + + +class TestLayoutMixin: + @staticmethod + def _create_template(env, model, **kw): + vals = { + "name": "Test Preview Template", + "subject": "Preview ${object.name}", + "body_html": '

Hello

', + "model_id": env["ir.model"]._get(model).id, + } + vals.update(kw) + return env["mail.template"].create(vals) + + +@tagged("-at_install", "post_install") +class TestLayoutPreview(TransactionCase, TestLayoutMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.wiz_model = cls.env["mail.template.preview"] + cls.partner = cls.env.ref("base.public_partner") + cls.tmpl = cls._create_template(cls.env, cls.partner._name) + + def test_wizard_preview_url(self): + wiz = self.wiz_model.create( + { + "mail_template_id": self.tmpl.id, + "resource_ref": f"{self.partner._name},{self.partner.id}", + } + ) + self.assertEqual( + wiz.layout_preview_url, + f"/email-preview/res.partner/{self.tmpl.id}/{self.partner.id}/", + ) + + +@tagged("-at_install", "post_install") +class TestController(HttpCase, TestLayoutMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + host = "127.0.0.1" + port = tools.config["http_port"] + cls.base_url = f"http://{host}:{port}/email-preview/" + + def test_controller1(self): + self.authenticate("admin", "admin") + model = "res.partner" + response = self.url_open(self.base_url + model) + content = response.content + tree = etree.fromstring(content) + list_items = tree.xpath("//ol[@class='email-template-list']/li/a") + templates = self.env["mail.template"].search( + Domain("model_id.model", "=", model) + ) + url_pattern = "/email-preview/res.partner/{templ_id}" + for el, tmpl in zip(list_items, templates, strict=False): + self.assertEqual(el.attrib["class"], "preview") + self.assertEqual( + el.attrib["href"], + url_pattern.format(templ_id=tmpl.id), + ) + + def test_controller2(self): + self.authenticate("admin", "admin") + partner = self.env.ref("base.public_partner") + model = partner._name + tmpl = self._create_template(self.env, model) + response = self.url_open(self.base_url + f"{model}/{tmpl.id}/{partner.id}/") + content = response.content.decode() + self.assertIn(f"

Hello {partner.name}

", content) diff --git a/mail_layout_preview/wizard/__init__.py b/mail_layout_preview/wizard/__init__.py new file mode 100644 index 000000000..134743a98 --- /dev/null +++ b/mail_layout_preview/wizard/__init__.py @@ -0,0 +1 @@ +from . import email_template_preview diff --git a/mail_layout_preview/wizard/email_template_preview.py b/mail_layout_preview/wizard/email_template_preview.py new file mode 100644 index 000000000..cb7af601d --- /dev/null +++ b/mail_layout_preview/wizard/email_template_preview.py @@ -0,0 +1,26 @@ +# Copyright 2020 Simone Orsi - Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import api, fields, models + + +class MailTemplatePreview(models.TransientModel): + _inherit = "mail.template.preview" + + _url_pattern = "/email-preview/{model}/{templ_id}/{rec_id}/" + + layout_preview_url = fields.Char( + string="Full layout preview", compute="_compute_layout_preview_url" + ) + + @api.depends("resource_ref", "model_id", "mail_template_id") + def _compute_layout_preview_url(self): + for rec in self: + if rec.mail_template_id and rec.resource_ref: + rec.layout_preview_url = self._url_pattern.format( + model=rec.model_id.model, + templ_id=rec.mail_template_id.id, + rec_id=rec.resource_ref.id, + ) + else: + rec.layout_preview_url = "" diff --git a/mail_layout_preview/wizard/email_template_preview.xml b/mail_layout_preview/wizard/email_template_preview.xml new file mode 100644 index 000000000..34b92fbb3 --- /dev/null +++ b/mail_layout_preview/wizard/email_template_preview.xml @@ -0,0 +1,16 @@ + + + + mail.template.preview + + + + + +