diff --git a/mail_inline_css/README.rst b/mail_inline_css/README.rst new file mode 100644 index 000000000..5c6e179ba --- /dev/null +++ b/mail_inline_css/README.rst @@ -0,0 +1,80 @@ +=============== +Mail Inline CSS +=============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/12.0/mail_inline_css + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_inline_css + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Convert styles to inline styles and make them play nice with emails. + +This module sole usage is to provide the same parsing functionality as in +the web editor but for the templates imported directly in database. + +**Table of contents** + +.. contents:: + :local: + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion +* camptocamp + +Contributors +~~~~~~~~~~~~ + +* David BEAL +* Akim Juillerat +* Simone Orsi +* Patrick Tombez + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_inline_css/__init__.py b/mail_inline_css/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mail_inline_css/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_inline_css/__manifest__.py b/mail_inline_css/__manifest__.py new file mode 100644 index 000000000..eee1fe77b --- /dev/null +++ b/mail_inline_css/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2017 David BEAL @ Akretion +# Copyright 2019 Camptocamp SA + +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Mail Inline CSS', + "summary": "Convert style tags in inline style in your mails", + 'version': '12.0.1.0.0', + 'author': 'Akretion, camptocamp, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/social', + 'license': 'AGPL-3', + 'category': 'Tools', + 'installable': True, + "external_dependencies": { + "python": ['premailer'], + }, + "depends": [ + "email_template_qweb", + ], + "demo": [ + "demo/demo_template.xml", + "demo/demo_mail_template.xml", + ], +} diff --git a/mail_inline_css/demo/demo_mail_template.xml b/mail_inline_css/demo/demo_mail_template.xml new file mode 100644 index 000000000..2a6d5f703 --- /dev/null +++ b/mail_inline_css/demo/demo_mail_template.xml @@ -0,0 +1,10 @@ + + + + Inline styles demo + qweb + + + Demo email inline styles + + diff --git a/mail_inline_css/demo/demo_template.xml b/mail_inline_css/demo/demo_template.xml new file mode 100644 index 000000000..3b80f5337 --- /dev/null +++ b/mail_inline_css/demo/demo_template.xml @@ -0,0 +1,84 @@ + + + + diff --git a/mail_inline_css/i18n/de.po b/mail_inline_css/i18n/de.po new file mode 100644 index 000000000..ec9d321d3 --- /dev/null +++ b/mail_inline_css/i18n/de.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Niki Waibel , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Niki Waibel , 2018\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "E-Mail Vorlagen" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/es.po b/mail_inline_css/i18n/es.po new file mode 100644 index 000000000..f057b9b01 --- /dev/null +++ b/mail_inline_css/i18n/es.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Pedro M. Baeza , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Pedro M. Baeza , 2018\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Plantillas de correo electrónico" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/es_MX.po b/mail_inline_css/i18n/es_MX.po new file mode 100644 index 000000000..d6e784f9d --- /dev/null +++ b/mail_inline_css/i18n/es_MX.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# OCA Transbot , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: OCA Transbot , 2018\n" +"Language-Team: Spanish (Mexico) (https://www.transifex.com/oca/teams/23907/" +"es_MX/)\n" +"Language: es_MX\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Plantillas de Correo Electrónico" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/fr.po b/mail_inline_css/i18n/fr.po new file mode 100644 index 000000000..adb110a3f --- /dev/null +++ b/mail_inline_css/i18n/fr.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Quentin THEURET , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Quentin THEURET , 2018\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Modèles de courriel" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/hr.po b/mail_inline_css/i18n/hr.po new file mode 100644 index 000000000..4300cfb94 --- /dev/null +++ b/mail_inline_css/i18n/hr.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# OCA Transbot , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: OCA Transbot , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Predlošci mailova" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/it.po b/mail_inline_css/i18n/it.po new file mode 100644 index 000000000..89c981513 --- /dev/null +++ b/mail_inline_css/i18n/it.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Marius Marolla , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Marius Marolla , 2018\n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Modelli Email" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/mail_inline_css.pot b/mail_inline_css/i18n/mail_inline_css.pot new file mode 100644 index 000000000..51a029de0 --- /dev/null +++ b/mail_inline_css/i18n/mail_inline_css.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "This e-mail styles are inline rendered although its template defines styles as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" + diff --git a/mail_inline_css/i18n/nl_NL.po b/mail_inline_css/i18n/nl_NL.po new file mode 100644 index 000000000..d852a29e7 --- /dev/null +++ b/mail_inline_css/i18n/nl_NL.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Peter Hageman , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Peter Hageman , 2018\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "E-mailsjablonen" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/zh_CN.po b/mail_inline_css/i18n/zh_CN.po new file mode 100644 index 000000000..3d6d2157a --- /dev/null +++ b/mail_inline_css/i18n/zh_CN.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# OCA Transbot , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: OCA Transbot , 2018\n" +"Language-Team: Chinese (China) (https://www.transifex.com/oca/teams/23907/" +"zh_CN/)\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Email 模板" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/models/__init__.py b/mail_inline_css/models/__init__.py new file mode 100644 index 000000000..44e83956e --- /dev/null +++ b/mail_inline_css/models/__init__.py @@ -0,0 +1 @@ +from . import mail_template diff --git a/mail_inline_css/models/mail_template.py b/mail_inline_css/models/mail_template.py new file mode 100644 index 000000000..82fdba83d --- /dev/null +++ b/mail_inline_css/models/mail_template.py @@ -0,0 +1,40 @@ +# Copyright 2017 David BEAL @ Akretion +# Copyright 2019 Camptocamp SA + +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + +try: + from premailer import Premailer +except (ImportError, IOError) as err: # pragma: no cover + import logging + _logger = logging.getLogger(__name__) + _logger.debug(err) + + +class MailTemplate(models.Model): + _inherit = 'mail.template' + + @api.multi + def generate_email(self, res_ids, fields=None): + """Use `premailer` to convert styles to inline styles.""" + result = super().generate_email(res_ids, fields=fields) + if isinstance(res_ids, int): + result['body_html'] = \ + self._premailer_apply_transform(result["body_html"]) + else: + for __, data in result.items(): + data['body_html'] = \ + self._premailer_apply_transform(data["body_html"]) + return result + + def _premailer_apply_transform(self, data_html): + premailer = Premailer( + html=data_html, + **self._get_premailer_options(), + ) + return premailer.transform() + + def _get_premailer_options(self): + return {} diff --git a/mail_inline_css/readme/CONTRIBUTORS.rst b/mail_inline_css/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..fcd33779b --- /dev/null +++ b/mail_inline_css/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* David BEAL +* Akim Juillerat +* Simone Orsi +* Patrick Tombez diff --git a/mail_inline_css/readme/DESCRIPTION.rst b/mail_inline_css/readme/DESCRIPTION.rst new file mode 100644 index 000000000..309573627 --- /dev/null +++ b/mail_inline_css/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Convert styles to inline styles and make them play nice with emails. + +This module sole usage is to provide the same parsing functionality as in +the web editor but for the templates imported directly in database. diff --git a/mail_inline_css/static/description/icon.png b/mail_inline_css/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_inline_css/static/description/icon.png differ diff --git a/mail_inline_css/static/description/index.html b/mail_inline_css/static/description/index.html new file mode 100644 index 000000000..0894a8330 --- /dev/null +++ b/mail_inline_css/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +Mail Inline CSS + + + +
+

Mail Inline CSS

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

Convert styles to inline styles and make them play nice with emails.

+

This module sole usage is to provide the same parsing functionality as in +the web editor but for the templates imported directly in database.

+

Table of contents

+ +
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
  • camptocamp
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_inline_css/tests/__init__.py b/mail_inline_css/tests/__init__.py new file mode 100644 index 000000000..464297637 --- /dev/null +++ b/mail_inline_css/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_inline_styles diff --git a/mail_inline_css/tests/test_mail_inline_styles.py b/mail_inline_css/tests/test_mail_inline_styles.py new file mode 100644 index 000000000..96e73bc16 --- /dev/null +++ b/mail_inline_css/tests/test_mail_inline_styles.py @@ -0,0 +1,62 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from lxml import html +from odoo.tests import SavepointCase + + +class TestMailInlineStyles(SavepointCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.mail_template = cls.env.ref( + 'mail_inline_css.email_template_demo') + cls.demo_user = cls.env.ref('base.user_demo') + + def to_xml_node(self, html_): + return html.fragments_fromstring(html_) + + def parse_node_style(self, node): + """ Convert node CSS string to Python dict""" + res = {} + for style in node.attrib.get('style', '').split(';'): + l = style.split(':') + res[l[0].strip()] = l[1].strip() + return res + + def find_by_id(self, node, html_id): + return node.xpath('//*[@id="{}"]'.format(html_id)) + + def assertNodeStyle(self, node, expected): + self.assertIn('style', node.attrib) + self.assertEqual(self.parse_node_style(node), expected) + + def test_generate_mail(self): + res = self.mail_template.generate_email( + [self.demo_user.id], fields=['body_html'] + ) + body_html_string = res[self.demo_user.id].get('body_html') + html_node = self.to_xml_node(body_html_string)[0] + + expected = { + 'main_logo': { + 'max-width': '300px' + }, + 'main_wrapper': { + 'max-width': '620px', + 'margin': '0 auto', + 'border': '1px solid #ccc', + 'font-size': '18px', + 'font-family': 'verdana', + 'color': '#6B6E71' + }, + 'main_footer': { + 'padding-top': '0', + 'font-size': '120%', + 'padding': '30px 40px' + } + } + + for html_id, expected_style in expected.items(): + node = self.find_by_id(html_node, html_id)[0] + self.assertNodeStyle(node, expected_style) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..cc65e05ab --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# mail_inline_css +premailer