[MIG] email_template_qweb: Migration to 15.0

pull/1072/head
fshah 2022-05-03 09:52:45 +05:30 committed by Dũng (Trần Đình)
parent 71d6107321
commit 71fdbcb4a3
11 changed files with 84 additions and 37 deletions

View File

@ -14,19 +14,19 @@ QWeb for email templates
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github .. |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 :alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/14.0 :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&target_branch=15.0
:alt: Try me on Runbot :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
This module was written to allow you to write email templates in QWeb instead This module was written to allow you to write email templates in `QWeb view` instead
of jinja2. The advantage here is that with QWeb, you can make use of 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 inheritance and the ``call`` statement, which allows you to reuse designs and
snippets in multiple templates, making your development process simpler. snippets in multiple templates, making your development process simpler.
Furthermore, QWeb views are easier to edit with the integrated ACE editor. Furthermore, QWeb views are easier to edit with the integrated ACE editor.
@ -41,9 +41,9 @@ Usage
To use this module, you need to: To use this module, you need to:
#. Select `QWeb` in the field `Body templating engine` #. Select `QWeb View` in the field `Body templating engine`
#. Select a QWeb view to be used to render the body field #. 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. #. 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 Bug Tracker
=========== ===========
@ -51,7 +51,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_. 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. 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 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. Do not contact contributors directly about support or help with technical issues.
@ -75,6 +75,9 @@ Contributors
* Thomas Fossoul (thomas@niboo.com) * Thomas Fossoul (thomas@niboo.com)
* Phuc Tran Thanh <phuc@trobz.com> * Phuc Tran Thanh <phuc@trobz.com>
* Foram Shah <foram.shah@initos.com>
* `Trobz <https://trobz.com>`_:
* Dzung Tran <dungtd@trobz.com>
Other credits 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 mission is to support the collaborative development of Odoo features and
promote its widespread use. 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. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "QWeb for email templates", "name": "QWeb for email templates",
"version": "14.0.1.0.1", "version": "15.0.1.0.0",
"author": "Therp BV, Odoo Community Association (OCA)", "author": "Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Marketing", "category": "Marketing",

View File

@ -10,7 +10,7 @@
<!-- if some template calling us sets this variable, <!-- if some template calling us sets this variable,
we print a h1 tag /--> we print a h1 tag /-->
<h1 t-if="email_heading"><t t-esc="email_heading" /></h1> <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 <!-- use some standard footer if the user doesn't have
a signature /--> a signature /-->
<footer t-if="not email_use_user_signature"> <footer t-if="not email_use_user_signature">
@ -22,7 +22,7 @@
<p><t t-esc="env.user.company_id.phone" /></p> <p><t t-esc="env.user.company_id.phone" /></p>
</footer> </footer>
<footer t-if="email_use_user_signature"> <footer t-if="email_use_user_signature">
<t t-raw="env.user.signature" /> <t t-out="env.user.signature" />
</footer> </footer>
</html> </html>
</body> </body>

View File

@ -2,7 +2,7 @@
<odoo> <odoo>
<record id="email_template_demo1" model="mail.template"> <record id="email_template_demo1" model="mail.template">
<field name="name">QWeb demo</field> <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="body_view_id" ref="view_email_template_demo1" />
<field name="model_id" ref="base.model_res_users" /> <field name="model_id" ref="base.model_res_users" />
<field name="subject">QWeb demo email</field> <field name="subject">QWeb demo email</field>

View File

@ -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"})

View File

@ -7,9 +7,9 @@ class MailTemplate(models.Model):
_inherit = "mail.template" _inherit = "mail.template"
body_type = fields.Selection( body_type = fields.Selection(
[("jinja2", "Jinja2"), ("qweb", "QWeb")], [("qweb", "QWeb"), ("qweb_view", "QWeb View")],
"Body templating engine", "Body templating engine",
default="jinja2", default="qweb",
required=True, required=True,
) )
body_view_id = fields.Many2one("ir.ui.view", domain=[("type", "=", "qweb")]) body_view_id = fields.Many2one("ir.ui.view", domain=[("type", "=", "qweb")])
@ -26,7 +26,9 @@ class MailTemplate(models.Model):
).items(): ).items():
self_with_lang = self.with_context(lang=lang) self_with_lang = self.with_context(lang=lang)
for res_id in res_ids: 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): for record in self_with_lang.env[self.model].browse(res_id):
body_html = self_with_lang.body_view_id._render( body_html = self_with_lang.body_view_id._render(
{"object": record, "email_template": self_with_lang} {"object": record, "email_template": self_with_lang}

View File

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

View File

@ -1,5 +1,5 @@
This module was written to allow you to write email templates in QWeb instead This module was written to allow you to write email templates in `QWeb view` instead
of jinja2. The advantage here is that with QWeb, you can make use of 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 inheritance and the ``call`` statement, which allows you to reuse designs and
snippets in multiple templates, making your development process simpler. snippets in multiple templates, making your development process simpler.
Furthermore, QWeb views are easier to edit with the integrated ACE editor. Furthermore, QWeb views are easier to edit with the integrated ACE editor.

View File

@ -1,5 +1,5 @@
To use this module, you need to: To use this module, you need to:
#. Select `QWeb` in the field `Body templating engine` #. Select `QWeb View` in the field `Body templating engine`
#. Select a QWeb view to be used to render the body field #. 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. #. 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.

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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> <title>QWeb for email templates</title>
<style type="text/css"> <style type="text/css">
@ -367,9 +367,9 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! 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><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 QWeb instead <p>This module was written to allow you to write email templates in <cite>QWeb view</cite> instead
of jinja2. The advantage here is that with QWeb, you can make use of 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 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. snippets in multiple templates, making your development process simpler.
Furthermore, QWeb views are easier to edit with the integrated ACE editor.</p> Furthermore, QWeb views are easier to edit with the integrated ACE editor.</p>
@ -391,9 +391,9 @@ Furthermore, QWeb views are easier to edit with the integrated ACE editor.</p>
<h1><a class="toc-backref" href="#id1">Usage</a></h1> <h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>To use this module, you need to:</p> <p>To use this module, you need to:</p>
<ol class="arabic simple"> <ol class="arabic simple">
<li>Select <cite>QWeb</cite> in the field <cite>Body templating engine</cite></li> <li>Select <cite>QWeb View</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>Select a <cite>QWeb View</cite> to be used to render the body field</li>
<li>Apart from QWebs 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>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> </ol>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
@ -401,7 +401,7 @@ Furthermore, QWeb views are easier to edit with the integrated ACE editor.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>. <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. 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 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> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -432,6 +432,16 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
</li> </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><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>
<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> </ul>
</div> </div>
<div class="section" id="other-credits"> <div class="section" id="other-credits">
@ -448,7 +458,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> 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> <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>
</div> </div>

View File

@ -8,22 +8,22 @@
<field name="body_type" /> <field name="body_type" />
</field> </field>
<field name="body_html" position="before"> <field name="body_html" position="before">
<group attrs="{'invisible': [('body_type', '!=', 'qweb')]}"> <group attrs="{'invisible': [('body_type', '!=', 'qweb_view')]}">
<field <field
name="body_view_id" name="body_view_id"
attrs="{'required': [('body_type', '=', 'qweb')]}" attrs="{'required': [('body_type', '=', 'qweb_view')]}"
/> />
<field <field
name="body_view_arch" name="body_view_arch"
widget="ace" widget="ace"
attrs="{'required': [('body_type', '=', 'qweb')], 'invisible': [('body_view_id', '=', False)]}" attrs="{'required': [('body_type', '=', 'qweb_view')], 'invisible': [('body_view_id', '=', False)]}"
/> />
</group> </group>
</field> </field>
<field name="body_html" position="attributes"> <field name="body_html" position="attributes">
<attribute <attribute
name="attrs" name="attrs"
>{'invisible': [('body_type', '!=', 'jinja2')]}</attribute> >{'invisible': [('body_type', '!=', 'qweb')]}</attribute>
</field> </field>
</field> </field>
</record> </record>