diff --git a/website_mail_qweb/README.rst b/website_mail_qweb/README.rst new file mode 100644 index 00000000..66559a8a --- /dev/null +++ b/website_mail_qweb/README.rst @@ -0,0 +1,64 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========================= +Edit QWeb email templates +========================= + +This module was written to make Odoo's WYSIWYG email template editor usable for email templates using the QWeb rendering engine. + +Usage +===== + +To use this module, you need to: + +#. click the 'Edit template' button on an email template +#. note that the editor supports designing and translating your templates, but for variable substitutions et al, you'll need to edit the source code of the template + +.. 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/8.0 + +Known issues / Roadmap +====================== + +* the editor has problems with complex template inheritance, this seems rather a problem in Odoo generally than with this specific module + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Holger Brunn + +Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/website_mail_qweb/__init__.py b/website_mail_qweb/__init__.py new file mode 100644 index 00000000..4fe02261 --- /dev/null +++ b/website_mail_qweb/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import controllers diff --git a/website_mail_qweb/__openerp__.py b/website_mail_qweb/__openerp__.py new file mode 100644 index 00000000..cc78b23a --- /dev/null +++ b/website_mail_qweb/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Edit QWeb email templates", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Hidden", + "summary": "Glue module to enable the wysiwyg editor for qweb email " + "templates", + "depends": [ + 'website_mail', + 'email_template_qweb', + ], + "data": [ + 'views/templates.xml', + ], + "auto_install": True, +} diff --git a/website_mail_qweb/controllers/__init__.py b/website_mail_qweb/controllers/__init__.py new file mode 100644 index 00000000..1b21ddd3 --- /dev/null +++ b/website_mail_qweb/controllers/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import main diff --git a/website_mail_qweb/controllers/main.py b/website_mail_qweb/controllers/main.py new file mode 100644 index 00000000..425f9d25 --- /dev/null +++ b/website_mail_qweb/controllers/main.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.addons.website_mail.controllers.email_designer import\ + WebsiteEmailDesigner +from openerp import http +from openerp.http import request + + +class UnquoteRecordset(object): + def __init__(self, recordset, name): + self.__recordset = recordset + self.__name = name + + def __getitem__(self, key): + if isinstance(key, basestring) and key in self.__recordset._fields: + return self.__recordset[key] + return UnquoteRecordset( + self.__recordset[key], '%s[%s]' % (self.__name, key) + ) + + def __getattr__(self, name): + recordset = self.__recordset + if name in recordset._fields: + if recordset._fields[name].relational: + return UnquoteRecordset( + recordset[name], '%s.%s' % (self.__name, name) + ) + elif recordset._fields[name].type in ('char', 'text'): + return '%s.%s' % (self.__name, name) + elif recordset._fields[name].type in ('integer', 'float'): + return 42 + else: + return recordset[name] + return getattr(recordset, name) + + +class Main(WebsiteEmailDesigner): + @http.route() + def index(self, model, res_id, template_model=None, **kw): + result = super(Main, self).index( + model, res_id, template_model=template_model, **kw + ) + env = request.env + qcontext = result.qcontext + record = qcontext.get('record', env['email.template'].new()) + if record.body_type == 'qweb': + qcontext['body_field'] = 'body_view_id' + qcontext['mode'] = 'email_designer' + qcontext['object'] = UnquoteRecordset( + env[record.model_id.model].new(), + 'object', + ) + qcontext['email_template'] = record + return result diff --git a/website_mail_qweb/static/description/icon.png b/website_mail_qweb/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/website_mail_qweb/static/description/icon.png differ diff --git a/website_mail_qweb/tests/__init__.py b/website_mail_qweb/tests/__init__.py new file mode 100644 index 00000000..18a43060 --- /dev/null +++ b/website_mail_qweb/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_website_mail_qweb diff --git a/website_mail_qweb/tests/test_website_mail_qweb.py b/website_mail_qweb/tests/test_website_mail_qweb.py new file mode 100644 index 00000000..bdb55f5e --- /dev/null +++ b/website_mail_qweb/tests/test_website_mail_qweb.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.tests.common import HttpCase +from ..controllers.main import UnquoteRecordset + + +class TestWebsiteMailQweb(HttpCase): + def test_website_mail_qweb(self): + self.authenticate('admin', 'admin') + result = self.url_open( + '/website_mail/email_designer?model=email.template&res_id=%s' % + self.env.ref('email_template_qweb.email_template_demo1').id + ) + self.assertIn('Dear object.name,', result.read()) + + def test_unquote_recordset(self): + record = UnquoteRecordset(self.env['res.partner'].new(), 'object') + self.assertEqual(record.name, 'object.name') + self.assertEqual(record.parent_id.name, 'object.parent_id.name') + self.assertEqual(record.id, 42) + self.assertEqual( + record.create_date, + self.env['res.partner']._fields['create_date'].null(self.env) + ) + self.assertEqual( + record[:1]['create_date'], + self.env['res.partner']._fields['create_date'].null(self.env) + ) + self.assertEqual(record._fields, self.env['res.partner']._fields) diff --git a/website_mail_qweb/views/templates.xml b/website_mail_qweb/views/templates.xml new file mode 100644 index 00000000..405ceb30 --- /dev/null +++ b/website_mail_qweb/views/templates.xml @@ -0,0 +1,12 @@ + + + + + +