[FIX] Parse generated html to remove to remove Odoo branding messages
This commit is contained in:
parent
ea65778460
commit
06da4d8041
@ -0,0 +1 @@
|
|||||||
|
from . import models
|
@ -3,16 +3,13 @@
|
|||||||
{
|
{
|
||||||
"name": "Mail Debrand",
|
"name": "Mail Debrand",
|
||||||
"summary": "Remove Odoo branding in sent emails",
|
"summary": "Remove Odoo branding in sent emails",
|
||||||
"version": "12.0.1.0.0",
|
"version": "12.0.2.0.0",
|
||||||
"category": "Social Network",
|
"category": "Social Network",
|
||||||
"website": "https://odoo-community.org/",
|
"website": "https://github.com/OCA/social/",
|
||||||
"author": "Odoo Community Association (OCA)",
|
"author": "Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"depends": [
|
"depends": [
|
||||||
"mail",
|
"mail",
|
||||||
],
|
],
|
||||||
"data": [
|
|
||||||
'views/mail_notification_view.xml'
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
1
mail_debrand/models/__init__.py
Normal file
1
mail_debrand/models/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import mail_template
|
42
mail_debrand/models/mail_template.py
Normal file
42
mail_debrand/models/mail_template.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Copyright 2019 O4SB - Graeme Gellatly
|
||||||
|
# Copyright 2019 Tecnativa - Ernesto Tejeda
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
from lxml import html as htmltree
|
||||||
|
import re
|
||||||
|
from odoo import _, api, models
|
||||||
|
|
||||||
|
|
||||||
|
class MailTemplate(models.Model):
|
||||||
|
_inherit = "mail.template"
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _debrand_body(self, html):
|
||||||
|
using_word = _('using')
|
||||||
|
odoo_word = _('Odoo')
|
||||||
|
html = re.sub(
|
||||||
|
using_word + "(.*)[\r\n]*(.*)>" + odoo_word + r"</a>", "", html,
|
||||||
|
)
|
||||||
|
powered_by = _("Powered by")
|
||||||
|
if powered_by not in html:
|
||||||
|
return html
|
||||||
|
root = htmltree.fromstring(html)
|
||||||
|
powered_by_elements = root.xpath(
|
||||||
|
"//*[text()[contains(.,'%s')]]" % powered_by
|
||||||
|
)
|
||||||
|
for elem in powered_by_elements:
|
||||||
|
# make sure it isn't a spurious powered by
|
||||||
|
if any(
|
||||||
|
[
|
||||||
|
"www.odoo.com" in child.get("href", "")
|
||||||
|
for child in elem.getchildren()
|
||||||
|
]
|
||||||
|
):
|
||||||
|
for child in elem.getchildren():
|
||||||
|
elem.remove(child)
|
||||||
|
elem.text = None
|
||||||
|
return htmltree.tostring(root).decode("utf-8")
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def render_post_process(self, html):
|
||||||
|
html = super().render_post_process(html)
|
||||||
|
return self._debrand_body(html)
|
1
mail_debrand/tests/__init__.py
Normal file
1
mail_debrand/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import test_mail_debrand
|
25
mail_debrand/tests/test_mail_debrand.py
Normal file
25
mail_debrand/tests/test_mail_debrand.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
|
class TestMailDebrand(common.TransactionCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.default_arch = self.env.ref(
|
||||||
|
'mail.message_notification_email'
|
||||||
|
).arch
|
||||||
|
self.paynow_arch = self.env.ref(
|
||||||
|
'mail.mail_notification_paynow'
|
||||||
|
).arch
|
||||||
|
|
||||||
|
def test_default_debrand(self):
|
||||||
|
self.assertIn('using', self.default_arch)
|
||||||
|
res = self.env["mail.template"]._debrand_body(self.default_arch)
|
||||||
|
self.assertNotIn('using', res)
|
||||||
|
|
||||||
|
def test_paynow_debrand(self):
|
||||||
|
self.assertIn('Powered by', self.paynow_arch)
|
||||||
|
res = self.env["mail.template"]._debrand_body(self.paynow_arch)
|
||||||
|
self.assertNotIn('Powered by', res)
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<odoo noupdate="1">
|
|
||||||
|
|
||||||
<template id="message_notification_email" inherit_id="mail.message_notification_email" priority="99">
|
|
||||||
<xpath expr="//div/p[last()]" position="replace" >
|
|
||||||
<p style="color: #555555; margin-top:32px;">
|
|
||||||
Sent by
|
|
||||||
<a t-if="website_url" t-att-href="website_url" style="text-decoration:none; color: #875A7B;">
|
|
||||||
<span t-esc="company.name"/>
|
|
||||||
</a>
|
|
||||||
<span t-if="not website_url" t-esc="company.name"/>
|
|
||||||
</p>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Replaces Powered By on these notifications -->
|
|
||||||
<template id="mail_notification_borders" inherit_id="mail.mail_notification_borders" priority="99">
|
|
||||||
<xpath expr="//tr[last()]" position="replace" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template id="mail_notification_light" inherit_id="mail.mail_notification_light" priority="99">
|
|
||||||
<xpath expr="//tr[last()]" position="replace" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template id="mail_notification_paynow" inherit_id="mail.mail_notification_paynow" priority="99">
|
|
||||||
<xpath expr="//tr[last()]" position="replace" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
</odoo>
|
|
Loading…
Reference in New Issue
Block a user