[11][MIG] email_template_qweb: Migration to 11.0

pull/1072/head
celm1990 2018-03-25 13:20:18 -05:00 committed by Dũng (Trần Đình)
parent 5ae4968f19
commit 5b7b097b87
7 changed files with 39 additions and 52 deletions

View File

@ -1,5 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg .. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:alt: License: AGPL-3 :target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
======================== ========================
QWeb for email templates QWeb for email templates
@ -16,45 +17,37 @@ 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` 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 #. 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.
``email_template``, which are browse records of the current object and the
email template in use, respectively.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0 :target: https://runbot.odoo-community.org/runbot/205/11.0
Demo data contains an example on how to separate corporate identity from a
template's content.
For further information, please visit:
* https://www.odoo.com/forum/help-1
Bug Tracker 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
In case of trouble, please check there if your issue has already been reported. check there if your issue has already been reported. If you spotted it first,
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback help us smash it by providing detailed and welcomed feedback.
`here <https://github.com/OCA/social/issues/new?body=module:%20email_template_qweb%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits Credits
======= =======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors Contributors
------------ ------------
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Dave Lasley <dave@laslabs.com> * Dave Lasley <dave@laslabs.com>
* Carlos Lopez Mite <celm1990@gmail.com>
Do not contact contributors directly about help with questions or problems concerning Do not contact contributors directly about support or help with technical issues.
this addon, but use the `forum <https://www.odoo.com/forum/help-1>`_,
the `community mailing list <mailto:community@mail.odoo.com>`_,
or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help,
and the bug tracker linked in `Bug Tracker`_ above for technical issues.
Maintainer Maintainer
---------- ----------

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # Copyright 2016 Therp BV <http://therp.nl>
# © 2016 Therp BV <http://therp.nl>
# 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).
from . import models from . import models

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*- # Copyright 2016 Therp BV <http://therp.nl>
# © 2016 Therp BV <http://therp.nl>
# 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": "10.0.1.0.0", "version": "11.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",
"summary": "Use the QWeb templating mechanism for emails", "summary": "Use the QWeb templating mechanism for emails",
'website': 'https://github.com/OCA/social',
"depends": [ "depends": [
'mail', 'mail',
], ],

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # Copyright 2016 Therp BV <http://therp.nl>
# © 2016 Therp BV <http://therp.nl>
# 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).
from . import mail_template from . import mail_template

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # Copyright 2016 Therp BV <http://therp.nl>
# © 2016 Therp BV <http://therp.nl>
# 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).
from odoo import api, fields, tools, models from odoo import api, fields, tools, models
@ -12,33 +11,32 @@ class MailTemplate(models.Model):
default='jinja2', required=True) default='jinja2', required=True)
body_view_id = fields.Many2one( body_view_id = fields.Many2one(
'ir.ui.view', 'Body view', domain=[('type', '=', 'qweb')]) 'ir.ui.view', 'Body view', domain=[('type', '=', 'qweb')])
body_view_arch = fields.Text(related=['body_view_id', 'arch']) body_view_arch = fields.Text(related='body_view_id.arch')
@api.multi @api.multi
def generate_email(self, res_ids, fields=None): def generate_email(self, res_ids, fields=None):
multi_mode = True multi_mode = True
if isinstance(res_ids, (int, long)): if isinstance(res_ids, int):
res_ids = [res_ids] res_ids = [res_ids]
multi_mode = False multi_mode = False
result = super(MailTemplate, self).generate_email( result = super(MailTemplate, self).generate_email(
res_ids, fields=fields res_ids, fields=fields
) )
for record_id, this in self.get_email_template(res_ids).iteritems(): for res_id, template in self.get_email_template(res_ids).items():
if this.body_type == 'qweb' and\ if template.body_type == 'qweb' and\
(not fields or 'body_html' in fields): (not fields or 'body_html' in fields):
for record in self.env[this.model].browse(record_id): for record in self.env[template.model].browse(res_id):
body_html = this.body_view_id.render({ body_html = template.body_view_id.render({
'object': record, 'object': record,
'email_template': this, 'email_template': template,
}) })
# Some wizards, like when sending a sales order, need this # Some wizards, like when sending a sales order, need this
# fix to display accents correctly # fix to display accents correctly
if not isinstance(body_html, unicode): body_html = tools.ustr(body_html)
body_html = body_html.decode('utf-8') result[res_id]['body_html'] = self.render_post_process(
result[record_id]['body_html'] = self.render_post_process(
body_html body_html
) )
result[record_id]['body'] = tools.html_sanitize( result[res_id]['body'] = tools.html_sanitize(
result[record_id]['body_html'] result[res_id]['body_html']
) )
return multi_mode and result or result[res_ids[0]] return multi_mode and result or result[res_ids[0]]

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # Copyright 2016 Therp BV <http://therp.nl>
# © 2016 Therp BV <http://therp.nl>
# 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).
from . import test_mail_template_qweb from . import test_mail_template_qweb

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # Copyright 2016 Therp BV <http://therp.nl>
# © 2016 Therp BV <http://therp.nl>
# 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).
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
@ -11,7 +10,7 @@ class TestMailTemplateQweb(TransactionCase):
self.assertTrue( self.assertTrue(
# this comes from the called template if everything worked # this comes from the called template if everything worked
'<footer>' in mail_values[self.env.user.id]['body_html'], '<footer>' in mail_values[self.env.user.id]['body_html'],
'Did not rcv rendered template in response. Got: \n%s\n' % ( 'Did not receive rendered template in response. Got: \n%s\n' % (
mail_values[self.env.user.id]['body_html'] mail_values[self.env.user.id]['body_html']
) )
) )
@ -20,7 +19,7 @@ class TestMailTemplateQweb(TransactionCase):
self.assertTrue( self.assertTrue(
# this comes from the called template if everything worked # this comes from the called template if everything worked
'<footer>' in mail_values['body_html'], '<footer>' in mail_values['body_html'],
'Did not rcv rendered template in response. Got: \n%s\n' % ( 'Did not receive rendered template in response. Got: \n%s\n' % (
mail_values['body_html'] mail_values['body_html']
) )
) )