From 71fdbcb4a327e6390cafb7e0b4ad857e8944c0f6 Mon Sep 17 00:00:00 2001 From: fshah Date: Tue, 3 May 2022 09:52:45 +0530 Subject: [PATCH] [MIG] email_template_qweb: Migration to 15.0 --- email_template_qweb/README.rst | 27 +++++++++-------- email_template_qweb/__manifest__.py | 2 +- email_template_qweb/demo/ir_ui_view.xml | 4 +-- email_template_qweb/demo/mail_template.xml | 2 +- .../migrations/15.0.1.0.0/pre-migration.py | 29 +++++++++++++++++++ email_template_qweb/models/mail_template.py | 8 +++-- email_template_qweb/readme/CONTRIBUTORS.rst | 3 ++ email_template_qweb/readme/DESCRIPTION.rst | 4 +-- email_template_qweb/readme/USAGE.rst | 6 ++-- .../static/description/index.html | 28 ++++++++++++------ email_template_qweb/views/mail_template.xml | 8 ++--- 11 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 email_template_qweb/migrations/15.0.1.0.0/pre-migration.py diff --git a/email_template_qweb/README.rst b/email_template_qweb/README.rst index 605af144f..f53852b06 100644 --- a/email_template_qweb/README.rst +++ b/email_template_qweb/README.rst @@ -14,19 +14,19 @@ QWeb for email templates :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/14.0/email_template_qweb + :target: https://github.com/OCA/social/tree/15.0/email_template_qweb :alt: OCA/social .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-email_template_qweb + :target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-email_template_qweb :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/14.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&target_branch=15.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -This module was written to allow you to write email templates in QWeb instead -of jinja2. The advantage here is that with QWeb, you can make use of +This module was written to allow you to write email templates in `QWeb view` instead +of QWeb. The advantage here is that with QWeb View, you can make use of inheritance and the ``call`` statement, which allows you to reuse designs and snippets in multiple templates, making your development process simpler. Furthermore, QWeb views are easier to edit with the integrated ACE editor. @@ -41,9 +41,9 @@ Usage To use this module, you need to: -#. Select `QWeb` in the field `Body templating engine` -#. Select a QWeb view to be used to render the body field -#. Apart from QWeb's standard variables, you also have access to ``object`` and ``email_template``, which are browse records of the current object and the email template in use, respectively. +#. Select `QWeb View` in the field `Body templating engine` +#. Select a `QWeb View` to be used to render the body field +#. Apart from `QWeb View` standard variables, you also have access to ``object`` and ``email_template``, which are browse records of the current object and the email template in use, respectively. Bug Tracker =========== @@ -51,7 +51,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. @@ -75,6 +75,9 @@ Contributors * Thomas Fossoul (thomas@niboo.com) * Phuc Tran Thanh +* Foram Shah +* `Trobz `_: + * Dzung Tran Other credits ~~~~~~~~~~~~~ @@ -96,6 +99,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/email_template_qweb/__manifest__.py b/email_template_qweb/__manifest__.py index a0e1e642e..08571d792 100644 --- a/email_template_qweb/__manifest__.py +++ b/email_template_qweb/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "QWeb for email templates", - "version": "14.0.1.0.1", + "version": "15.0.1.0.0", "author": "Therp BV, Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Marketing", diff --git a/email_template_qweb/demo/ir_ui_view.xml b/email_template_qweb/demo/ir_ui_view.xml index e7e3fb0fa..e58921452 100644 --- a/email_template_qweb/demo/ir_ui_view.xml +++ b/email_template_qweb/demo/ir_ui_view.xml @@ -10,7 +10,7 @@

- +
@@ -22,7 +22,7 @@

- +
diff --git a/email_template_qweb/demo/mail_template.xml b/email_template_qweb/demo/mail_template.xml index 6ef1c61ce..254b9d5f9 100644 --- a/email_template_qweb/demo/mail_template.xml +++ b/email_template_qweb/demo/mail_template.xml @@ -2,7 +2,7 @@ QWeb demo - qweb + qweb_view QWeb demo email diff --git a/email_template_qweb/migrations/15.0.1.0.0/pre-migration.py b/email_template_qweb/migrations/15.0.1.0.0/pre-migration.py new file mode 100644 index 000000000..9dc272db9 --- /dev/null +++ b/email_template_qweb/migrations/15.0.1.0.0/pre-migration.py @@ -0,0 +1,29 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import SUPERUSER_ID, api + + +def migrate(cr, version): + if not version: + return + + env = api.Environment(cr, SUPERUSER_ID, {}) + body_type = env["ir.model.fields"].search( + [("name", "=", "body_type"), ("model", "=", "mail.template")] + ) + + # Note: no need to migrate the existing values of the `body_type` of the + # model `mail_template` because Odoo already does it + # See https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/models/ir_model.py#L1351 + if body_type: + # qweb -> qweb_view + qweb = env["ir.model.fields.selection"].search( + [("value", "=", "qweb"), ("field_id", "=", body_type.id)] + ) + qweb.write({"value": "qweb_view"}) + + # jinja2 -> qweb + jinja = env["ir.model.fields.selection"].search( + [("value", "=", "jinja2"), ("field_id", "=", body_type.id)] + ) + jinja.write({"value": "qweb"}) diff --git a/email_template_qweb/models/mail_template.py b/email_template_qweb/models/mail_template.py index 3d92af666..33dbbd2a9 100644 --- a/email_template_qweb/models/mail_template.py +++ b/email_template_qweb/models/mail_template.py @@ -7,9 +7,9 @@ class MailTemplate(models.Model): _inherit = "mail.template" body_type = fields.Selection( - [("jinja2", "Jinja2"), ("qweb", "QWeb")], + [("qweb", "QWeb"), ("qweb_view", "QWeb View")], "Body templating engine", - default="jinja2", + default="qweb", required=True, ) body_view_id = fields.Many2one("ir.ui.view", domain=[("type", "=", "qweb")]) @@ -26,7 +26,9 @@ class MailTemplate(models.Model): ).items(): self_with_lang = self.with_context(lang=lang) for res_id in res_ids: - if self.body_type == "qweb" and (not fields or "body_html" in fields): + if self.body_type == "qweb_view" and ( + not fields or "body_html" in fields + ): for record in self_with_lang.env[self.model].browse(res_id): body_html = self_with_lang.body_view_id._render( {"object": record, "email_template": self_with_lang} diff --git a/email_template_qweb/readme/CONTRIBUTORS.rst b/email_template_qweb/readme/CONTRIBUTORS.rst index cf30deb81..7d8120af9 100644 --- a/email_template_qweb/readme/CONTRIBUTORS.rst +++ b/email_template_qweb/readme/CONTRIBUTORS.rst @@ -7,3 +7,6 @@ * Thomas Fossoul (thomas@niboo.com) * Phuc Tran Thanh +* Foram Shah +* `Trobz `_: + * Dzung Tran diff --git a/email_template_qweb/readme/DESCRIPTION.rst b/email_template_qweb/readme/DESCRIPTION.rst index 71f9ece9d..7b4eec638 100644 --- a/email_template_qweb/readme/DESCRIPTION.rst +++ b/email_template_qweb/readme/DESCRIPTION.rst @@ -1,5 +1,5 @@ -This module was written to allow you to write email templates in QWeb instead -of jinja2. The advantage here is that with QWeb, you can make use of +This module was written to allow you to write email templates in `QWeb view` instead +of QWeb. The advantage here is that with QWeb View, you can make use of inheritance and the ``call`` statement, which allows you to reuse designs and snippets in multiple templates, making your development process simpler. Furthermore, QWeb views are easier to edit with the integrated ACE editor. diff --git a/email_template_qweb/readme/USAGE.rst b/email_template_qweb/readme/USAGE.rst index 67eb0b21d..e28141b24 100644 --- a/email_template_qweb/readme/USAGE.rst +++ b/email_template_qweb/readme/USAGE.rst @@ -1,5 +1,5 @@ To use this module, you need to: -#. Select `QWeb` in the field `Body templating engine` -#. Select a QWeb view to be used to render the body field -#. Apart from QWeb's standard variables, you also have access to ``object`` and ``email_template``, which are browse records of the current object and the email template in use, respectively. +#. Select `QWeb View` in the field `Body templating engine` +#. Select a `QWeb View` to be used to render the body field +#. Apart from `QWeb View` standard variables, you also have access to ``object`` and ``email_template``, which are browse records of the current object and the email template in use, respectively. diff --git a/email_template_qweb/static/description/index.html b/email_template_qweb/static/description/index.html index 13a5e06bb..3a46686fc 100644 --- a/email_template_qweb/static/description/index.html +++ b/email_template_qweb/static/description/index.html @@ -3,7 +3,7 @@ - + QWeb for email templates