Skip to content

Commit

Permalink
[18.0][MIG] mail_inline_css: Migrate to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kv1612 authored and nguyenminhchien committed Nov 13, 2024
1 parent 00c9390 commit 564e39f
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 132 deletions.
33 changes: 17 additions & 16 deletions mail_inline_css/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Mail Inline CSS
.. |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/18.0/mail_inline_css
:alt: OCA/social
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
:target: https://github.com/OCA/mail/tree/18.0/mail_inline_css
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_inline_css
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_inline_css
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -41,10 +41,10 @@ in the web editor but for the templates imported directly in database.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_inline_css%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_inline_css%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand All @@ -60,24 +60,25 @@ Authors
Contributors
------------

- David BEAL <david.beal@akretion.com>
- David BEAL <david.beal@akretion.com>

- Akim Juillerat <akim.juillerat@camptocamp.com>
- Akim Juillerat <akim.juillerat@camptocamp.com>

- Simone Orsi <simone.orsi@camptocamp.com>
- Simone Orsi <simone.orsi@camptocamp.com>

- Patrick Tombez <patrick.tombez@camptocamp.com>
- Patrick Tombez <patrick.tombez@camptocamp.com>

- Phuc Tran Thanh <phuc@trobz.com>
- Phuc Tran Thanh <phuc@trobz.com>

- `Trobz <https://trobz.com>`__:
- `Trobz <https://trobz.com>`__:

- Son Ho <sonhd@trobz.com>
- Son Ho <sonhd@trobz.com>
- Khoi Vo <khoivha@trobz.com>

Other credits
-------------

The migration of this module from 15.0 to 16.0 was financially supported
The migration of this module from 16.0 to 18.0 was financially supported
by Camptocamp

Maintainers
Expand All @@ -93,6 +94,6 @@ 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 <https://github.com/OCA/social/tree/18.0/mail_inline_css>`_ project on GitHub.
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_inline_css>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 4 additions & 4 deletions mail_inline_css/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
{
"name": "Mail Inline CSS",
"summary": "Convert style tags in inline style in your mails",
"version": "16.0.0.1.0",
"version": "18.0.1.0.0",
"author": "Akretion, camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"website": "https://github.com/OCA/mail",
"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"],
"depends": ["mail"],
"demo": ["demo/demo_mail_template.xml"],
}
96 changes: 94 additions & 2 deletions mail_inline_css/demo/demo_mail_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,101 @@
<odoo noupdate="0">
<record id="email_template_demo" model="mail.template">
<field name="name">Inline styles demo</field>
<field name="body_type">qweb_view</field>
<field name="body_view_id" ref="demo_email_hello" />
<field name="model_id" ref="base.model_res_users" />
<field name="subject">Demo email inline styles</field>
<field name="body_html" type="html">
<html>
<body>
<!-- TODO: move to LESS file
If we put the link as it is `premailer` won't be able to render it.
To ease this, we could:
1. find the less file on FS
2. compile to less
3. populate style block
-->
<style>
#main_wrapper {
max-width: 620px;
margin: 0 auto;
border: 1px solid #ccc;
font-size: 18px;
font-family: verdana;
color: #6B6E71;
}
a { color: #3BA0A6; text-decoration: none }
#main_header, footer, main div { padding: 30px 40px }
#main_header table { width: 100% }
#main_header table td { width: 50% }
#main_logo { max-width: 300px }
#main_header .right {
text-align: right;
vertical-align: top;
font-size: 140%;
}
#main_header .date_today { text-transform: uppercase; opacity: 0.7; color: #FF0000 }
footer { padding-top: 0; font-size: 120% }
footer address { font-style: normal }
.greeting { padding-top: 0; padding-bottom: 0 }
.image-wrapper {
min-height: 250px;
}
.image-wrapper.location-map {
margin: 0 -40px;
}
.pt0 { padding-top: 0 }
a.contact { cursor: pointer }
</style>
<div id="main_wrapper">
<div id="main_header">
<table>
<tbody>
<tr>
<td class="left">
<img
id="main_logo"
t-attf-src="data:image;base64,{{env.user.company_id.logo}}"
/>
</td>
<td class="right">
<span
class="date_today"
t-esc="time.strftime('%%d %%B %%Y')"
/>
</td>
</tr>
</tbody>
</table>
</div>
<main id="main_content">
<div class="greeting">
<p>Hello <span t-field="object.name" />.</p>
</div>
<div id="content">
<p
>This e-mail styles are inline rendered although its template defines styles as embedded CSS!</p>
</div>
</main>
<footer id="main_footer">
<div class="company_info">
<p class="website">
<a
href="https://www.example.com"
>www.example.com</a>
</p>
<div class="address">
<div
t-field="env.user.company_id.partner_id"
t-options='{
"widget": "contact",
"fields": ["name", "address", "phone", "mobile", "email"]
}'
/>
</div>
</div>
</footer>
</div>
</body>
</html>
</field>
</record>
</odoo>
92 changes: 0 additions & 92 deletions mail_inline_css/demo/demo_template.xml

This file was deleted.

14 changes: 4 additions & 10 deletions mail_inline_css/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@

# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models

try:
from premailer import Premailer
except (OSError, ImportError) as err: # pragma: no cover
import logging
from premailer import Premailer

_logger = logging.getLogger(__name__)
_logger.debug(err)
from odoo import models


class MailTemplate(models.Model):
_inherit = "mail.template"

def _render_template_postprocess(self, rendered):
rendered = super()._render_template_postprocess(rendered)
def _render_template_postprocess(self, model, rendered):
rendered = super()._render_template_postprocess(model, rendered)
for res_id, html in rendered.items():
rendered[res_id] = self._premailer_apply_transform(html)
return rendered
Expand Down
1 change: 1 addition & 0 deletions mail_inline_css/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- [Trobz](https://trobz.com):

> - Son Ho \<<sonhd@trobz.com>\>
> - Khoi Vo \<<khoivha@trobz.com>\>
2 changes: 1 addition & 1 deletion mail_inline_css/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
The migration of this module from 15.0 to 16.0 was financially supported
The migration of this module from 16.0 to 18.0 was financially supported
by Camptocamp
11 changes: 6 additions & 5 deletions mail_inline_css/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Mail Inline CSS</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e3cd02099a2beb9db6980920f3d0547a5154e4a386f2f3e3bf189342a85a2110
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/18.0/mail_inline_css"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_inline_css"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/mail/tree/18.0/mail_inline_css"><img alt="OCA/mail" src="https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_inline_css"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/mail&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Convert styles to inline styles and make them play nice with emails.</p>
<p>This module sole usage is to provide the same parsing functionality as
in the web editor but for the templates imported directly in database.</p>
Expand All @@ -388,10 +388,10 @@ <h1 class="title">Mail Inline CSS</h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/mail/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_inline_css%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/mail/issues/new?body=module:%20mail_inline_css%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -420,14 +420,15 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<blockquote>
<ul class="simple">
<li>Son Ho &lt;<a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a>&gt;</li>
<li>Khoi Vo &lt;<a class="reference external" href="mailto:khoivha&#64;trobz.com">khoivha&#64;trobz.com</a>&gt;</li>
</ul>
</blockquote>
</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<p>The migration of this module from 15.0 to 16.0 was financially supported
<p>The migration of this module from 16.0 to 18.0 was financially supported
by Camptocamp</p>
</div>
<div class="section" id="maintainers">
Expand All @@ -439,7 +440,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/18.0/mail_inline_css">OCA/social</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/mail/tree/18.0/mail_inline_css">OCA/mail</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions mail_inline_css/tests/test_mail_inline_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def assertNodeStyle(self, node, expected):
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"]
res = self.mail_template._generate_template(
[self.demo_user.id], render_fields=["body_html"]
)
body_html_string = res[self.demo_user.id].get("body_html")
html_node = self.to_xml_node(body_html_string)[0]
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generated from manifests external_dependencies
premailer

0 comments on commit 564e39f

Please sign in to comment.