Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] email_template_qweb: Migration to 15.0 #1072

Merged
merged 32 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ac433de
[ADD] email_template_qweb
lasley May 18, 2016
b91a17e
[FIX] Call to generate_email can be done with a list of ids or only o…
lmignon May 30, 2016
00aa465
[MIG] email_template_qweb: Migrated to 10.0
bouvyd Oct 11, 2016
daee701
[FIX] email_template_qweb: Decode body when encoded
pedrobaeza Oct 17, 2016
5ae4968
OCA Transbot updated translations from Transifex
oca-transbot May 22, 2016
5b7b097
[11][MIG] email_template_qweb: Migration to 11.0
celm1990 Mar 25, 2018
f9f725c
[UPD] Update email_template_qweb.pot
oca-travis Jun 17, 2018
ec3b55a
[MIG] email_template_qweb: Migration to 12.0
ernestotejeda Dec 12, 2018
48a4c37
[UPD] README.rst
OCA-git-bot Dec 20, 2018
5ae8ed0
[UPD] Update email_template_qweb.pot
oca-travis Dec 20, 2018
6e5a314
Update translation files
oca-transbot Dec 29, 2018
5701595
[UPD] README.rst
OCA-git-bot Jul 29, 2019
6ab0d55
Translated using Weblate (Portuguese (Brazil))
Sep 3, 2019
17ba39b
Translated using Weblate (Portuguese (Brazil))
Sep 17, 2019
5382bde
[IMP] email_template_qweb: black, isort
tfossoul Jan 2, 2020
d2697b5
[MIG] email_template_qweb: Migration to 13.0
tfossoul Jan 2, 2020
8830fc3
[UPD] Update email_template_qweb.pot
oca-travis Jan 17, 2020
6e0ee0b
[UPD] README.rst
OCA-git-bot Jan 17, 2020
703a9e0
Update translation files
oca-transbot Jan 31, 2020
2feb0bf
Update translation files
oca-transbot Aug 16, 2020
5b2ef9a
[IMP] pre-commit run -a
Jan 26, 2021
acb36f7
[MIG] email_template_qweb: Migration to 14.0
phuctranfxvn Feb 23, 2021
43dec7b
[UPD] Update email_template_qweb.pot
oca-travis Feb 28, 2021
ec72cef
[UPD] README.rst
OCA-git-bot Feb 28, 2021
95d06b5
Translated using Weblate (French)
Yvesldff Mar 22, 2021
0030f88
Added translation using Weblate (French (France))
Yvesldff Apr 11, 2021
d5655dc
Translated using Weblate (French (France))
Yvesldff Apr 11, 2021
00e58b8
[FIX] email_template_qweb: get translations working
sebalix Mar 23, 2022
23454b0
email_template_qweb 14.0.1.0.1
OCA-git-bot Apr 22, 2022
1bd1fc2
[IMP] update dotfiles [ci skip]
OCA-git-bot Dec 11, 2022
71d6107
[IMP] email_template_qweb: black, isort, prettier
dzungtran89 Feb 14, 2023
71fdbcb
[MIG] email_template_qweb: Migration to 15.0
fshah-initos May 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions email_template_qweb/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,17 +41,17 @@ 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
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/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 <https://github.com/OCA/social/issues/new?body=module:%20email_template_qweb%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/social/issues/new?body=module:%20email_template_qweb%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand All @@ -75,6 +75,9 @@ Contributors

* Thomas Fossoul (thomas@niboo.com)
* Phuc Tran Thanh <phuc@trobz.com>
* Foram Shah <foram.shah@initos.com>
* `Trobz <https://trobz.com>`_:
* Dzung Tran <dungtd@trobz.com>

Other credits
~~~~~~~~~~~~~
Expand All @@ -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 <https://github.com/OCA/social/tree/14.0/email_template_qweb>`_ project on GitHub.
This module is part of the `OCA/social <https://github.com/OCA/social/tree/15.0/email_template_qweb>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion email_template_qweb/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions email_template_qweb/demo/ir_ui_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- if some template calling us sets this variable,
we print a h1 tag /-->
<h1 t-if="email_heading"><t t-esc="email_heading" /></h1>
<t t-raw="0" />
<t t-out="0" />
<!-- use some standard footer if the user doesn't have
a signature /-->
<footer t-if="not email_use_user_signature">
Expand All @@ -22,7 +22,7 @@
<p><t t-esc="env.user.company_id.phone" /></p>
</footer>
<footer t-if="email_use_user_signature">
<t t-raw="env.user.signature" />
<t t-out="env.user.signature" />
</footer>
</html>
</body>
Expand Down
2 changes: 1 addition & 1 deletion email_template_qweb/demo/mail_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<odoo>
<record id="email_template_demo1" model="mail.template">
<field name="name">QWeb demo</field>
<field name="body_type">qweb</field>
<field name="body_type">qweb_view</field>
<field name="body_view_id" ref="view_email_template_demo1" />
<field name="model_id" ref="base.model_res_users" />
<field name="subject">QWeb demo email</field>
Expand Down
29 changes: 29 additions & 0 deletions email_template_qweb/migrations/15.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -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"})
8 changes: 5 additions & 3 deletions email_template_qweb/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")])
Expand All @@ -26,7 +26,9 @@ def generate_email(self, res_ids, fields):
).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
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you by now override https://github.com/odoo/odoo/blob/15.0/addons/mail/models/mail_render_mixin.py#L565 and just pass the value of body_type in engine?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually renders a mail template, while this tries to take the predefined views to render the mail's body

Copy link
Member

@hbrunn hbrunn Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what the module is doing because I'm it's original author ;-)

But now I see this function insists on views with an xmlid for that case, so it's indeed not usable for our case

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}
Expand Down
3 changes: 3 additions & 0 deletions email_template_qweb/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

* Thomas Fossoul (thomas@niboo.com)
* Phuc Tran Thanh <phuc@trobz.com>
* Foram Shah <foram.shah@initos.com>
* `Trobz <https://trobz.com>`_:
* Dzung Tran <dungtd@trobz.com>
4 changes: 2 additions & 2 deletions email_template_qweb/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions email_template_qweb/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 19 additions & 9 deletions email_template_qweb/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>QWeb for email templates</title>
<style type="text/css">

Expand Down Expand Up @@ -367,9 +367,9 @@ <h1 class="title">QWeb for email templates</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/14.0/email_template_qweb"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-14-0/social-14-0-email_template_qweb"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>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
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/15.0/email_template_qweb"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-15-0/social-15-0-email_template_qweb"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to allow you to write email templates in <cite>QWeb view</cite> instead
of QWeb. The advantage here is that with QWeb View, you can make use of
inheritance and the <tt class="docutils literal">call</tt> 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.</p>
Expand All @@ -391,17 +391,17 @@ <h1 class="title">QWeb for email templates</h1>
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Select <cite>QWeb</cite> in the field <cite>Body templating engine</cite></li>
<li>Select a QWeb view to be used to render the body field</li>
<li>Apart from QWeb’s standard variables, you also have access to <tt class="docutils literal">object</tt> and <tt class="docutils literal">email_template</tt>, which are browse records of the current object and the email template in use, respectively.</li>
<li>Select <cite>QWeb View</cite> in the field <cite>Body templating engine</cite></li>
<li>Select a <cite>QWeb View</cite> to be used to render the body field</li>
<li>Apart from <cite>QWeb View</cite> standard variables, you also have access to <tt class="docutils literal">object</tt> and <tt class="docutils literal">email_template</tt>, which are browse records of the current object and the email template in use, respectively.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20email_template_qweb%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20email_template_qweb%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -432,6 +432,16 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
</li>
<li><p class="first">Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</p>
</li>
<li><p class="first">Foram Shah &lt;<a class="reference external" href="mailto:foram.shah&#64;initos.com">foram.shah&#64;initos.com</a>&gt;</p>
</li>
<li><dl class="first docutils">
<dt><a class="reference external" href="https://trobz.com">Trobz</a>:</dt>
<dd><ul class="first last simple">
<li>Dzung Tran &lt;<a class="reference external" href="mailto:dungtd&#64;trobz.com">dungtd&#64;trobz.com</a>&gt;</li>
</ul>
</dd>
</dl>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -448,7 +458,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/14.0/email_template_qweb">OCA/social</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/15.0/email_template_qweb">OCA/social</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions email_template_qweb/views/mail_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
<field name="body_type" />
</field>
<field name="body_html" position="before">
<group attrs="{'invisible': [('body_type', '!=', 'qweb')]}">
<group attrs="{'invisible': [('body_type', '!=', 'qweb_view')]}">
<field
name="body_view_id"
attrs="{'required': [('body_type', '=', 'qweb')]}"
attrs="{'required': [('body_type', '=', 'qweb_view')]}"
/>
<field
name="body_view_arch"
widget="ace"
attrs="{'required': [('body_type', '=', 'qweb')], 'invisible': [('body_view_id', '=', False)]}"
attrs="{'required': [('body_type', '=', 'qweb_view')], 'invisible': [('body_view_id', '=', False)]}"
/>
</group>
</field>
<field name="body_html" position="attributes">
<attribute
name="attrs"
>{'invisible': [('body_type', '!=', 'jinja2')]}</attribute>
>{'invisible': [('body_type', '!=', 'qweb')]}</attribute>
</field>
</field>
</record>
Expand Down