Browse Source

[11][MIG] email_template_qweb: Migration to 11.0

pull/250/head
celm1990 7 years ago
committed by Pedro M. Baeza
parent
commit
80436ac23e
  1. 43
      email_template_qweb/README.rst
  2. 3
      email_template_qweb/__init__.py
  3. 6
      email_template_qweb/__manifest__.py
  4. 3
      email_template_qweb/models/__init__.py
  5. 26
      email_template_qweb/models/mail_template.py
  6. 3
      email_template_qweb/tests/__init__.py
  7. 7
      email_template_qweb/tests/test_mail_template_qweb.py

43
email_template_qweb/README.rst

@ -1,5 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
: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 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` 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.
.. 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
:target: https://runbot.odoo-community.org/runbot/205/10.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
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/11.0
Bug Tracker 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
`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**>`_.
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 smash it by providing detailed and welcomed feedback.
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
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.
Do not contact contributors directly about support or help with technical issues.
Maintainer Maintainer
---------- ----------

3
email_template_qweb/__init__.py

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

6
email_template_qweb/__manifest__.py

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# Copyright 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',
], ],

3
email_template_qweb/models/__init__.py

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

26
email_template_qweb/models/mail_template.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# Copyright 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():
if this.body_type == 'qweb' and\
for res_id, template in self.get_email_template(res_ids).items():
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):
body_html = this.body_view_id.render({
for record in self.env[template.model].browse(res_id):
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 = body_html.decode('utf-8')
result[record_id]['body_html'] = self.render_post_process(
body_html = tools.ustr(body_html)
result[res_id]['body_html'] = self.render_post_process(
body_html body_html
) )
result[record_id]['body'] = tools.html_sanitize(
result[record_id]['body_html']
result[res_id]['body'] = tools.html_sanitize(
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]]

3
email_template_qweb/tests/__init__.py

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

7
email_template_qweb/tests/test_mail_template_qweb.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# Copyright 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']
) )
) )
Loading…
Cancel
Save