From 0d390c9a0f68797eb207832f6482e0892592087b Mon Sep 17 00:00:00 2001 From: celm1990 Date: Sun, 25 Mar 2018 13:20:18 -0500 Subject: [PATCH] [11][MIG] email_template_qweb: Migration to 11.0 --- email_template_qweb/README.rst | 43 ++++++++----------- email_template_qweb/__init__.py | 3 +- email_template_qweb/__manifest__.py | 6 +-- email_template_qweb/models/__init__.py | 3 +- email_template_qweb/models/mail_template.py | 26 ++++++----- email_template_qweb/tests/__init__.py | 3 +- .../tests/test_mail_template_qweb.py | 7 ++- 7 files changed, 39 insertions(+), 52 deletions(-) diff --git a/email_template_qweb/README.rst b/email_template_qweb/README.rst index 7e99df82..01e4b7e4 100644 --- a/email_template_qweb/README.rst +++ b/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 @@ -16,45 +17,37 @@ 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` 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 - :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 =========== -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 -`here `_. +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 smash it by providing detailed and welcomed feedback. Credits ======= +Images +------ + +* Odoo Community Association: `Icon `_. + Contributors ------------ * Holger Brunn * Dave Lasley +* Carlos Lopez Mite -Do not contact contributors directly about help with questions or problems concerning -this addon, but use the `forum `_, -the `community mailing list `_, -or the `appropriate specialized mailinglist `_ 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 ---------- diff --git a/email_template_qweb/__init__.py b/email_template_qweb/__init__.py index 7eda98a2..8d7f2c4b 100644 --- a/email_template_qweb/__init__.py +++ b/email_template_qweb/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- -# © 2016 Therp BV +# Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/email_template_qweb/__manifest__.py b/email_template_qweb/__manifest__.py index cdc8caa4..e9f01b27 100644 --- a/email_template_qweb/__manifest__.py +++ b/email_template_qweb/__manifest__.py @@ -1,13 +1,13 @@ -# -*- coding: utf-8 -*- -# © 2016 Therp BV +# Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "QWeb for email templates", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Marketing", "summary": "Use the QWeb templating mechanism for emails", + 'website': 'https://github.com/OCA/social', "depends": [ 'mail', ], diff --git a/email_template_qweb/models/__init__.py b/email_template_qweb/models/__init__.py index ed59ea76..c4b95e3c 100644 --- a/email_template_qweb/models/__init__.py +++ b/email_template_qweb/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- -# © 2016 Therp BV +# Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import mail_template diff --git a/email_template_qweb/models/mail_template.py b/email_template_qweb/models/mail_template.py index a3c99051..0f87a082 100644 --- a/email_template_qweb/models/mail_template.py +++ b/email_template_qweb/models/mail_template.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2016 Therp BV +# Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, fields, tools, models @@ -12,33 +11,32 @@ class MailTemplate(models.Model): default='jinja2', required=True) body_view_id = fields.Many2one( '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 def generate_email(self, res_ids, fields=None): multi_mode = True - if isinstance(res_ids, (int, long)): + if isinstance(res_ids, int): res_ids = [res_ids] multi_mode = False result = super(MailTemplate, self).generate_email( 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): - 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, - 'email_template': this, + 'email_template': template, }) # Some wizards, like when sending a sales order, need this # 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 ) - 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]] diff --git a/email_template_qweb/tests/__init__.py b/email_template_qweb/tests/__init__.py index 4e89ae38..b6c15930 100644 --- a/email_template_qweb/tests/__init__.py +++ b/email_template_qweb/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- -# © 2016 Therp BV +# Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import test_mail_template_qweb diff --git a/email_template_qweb/tests/test_mail_template_qweb.py b/email_template_qweb/tests/test_mail_template_qweb.py index 024a81d4..6f789d48 100644 --- a/email_template_qweb/tests/test_mail_template_qweb.py +++ b/email_template_qweb/tests/test_mail_template_qweb.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2016 Therp BV +# Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase @@ -11,7 +10,7 @@ class TestMailTemplateQweb(TransactionCase): self.assertTrue( # this comes from the called template if everything worked '