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 5, 2024
1 parent e6b589b commit 5972937
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 119 deletions.
17 changes: 9 additions & 8 deletions mail_inline_css/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,25 @@ Authors
Contributors
------------

- David BEAL <[email protected]>
- David BEAL <[email protected]>

- Akim Juillerat <[email protected]>
- Akim Juillerat <[email protected]>

- Simone Orsi <[email protected]>
- Simone Orsi <[email protected]>

- Patrick Tombez <[email protected]>
- Patrick Tombez <[email protected]>

- Phuc Tran Thanh <[email protected]>
- Phuc Tran Thanh <[email protected]>

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

- Son Ho <[email protected]>
- Son Ho <[email protected]>
- Khoi Vo <[email protected]>

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 Down
6 changes: 3 additions & 3 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",
"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 \<<[email protected]>\>
> - Khoi Vo \<<[email protected]>\>
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
3 changes: 2 additions & 1 deletion mail_inline_css/static/description/index.html
Original file line number Diff line number Diff line change
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 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 5972937

Please sign in to comment.