Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mail_debrand/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
7 changes: 2 additions & 5 deletions mail_debrand/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

{
"name": "Mail Debrand",
"summary": "Remove Odoo branding in sent emails",
"version": "12.0.1.0.0",
"summary": "Remove Odoo branding in sent emails.",
"version": "12.0.2.0.0",
"category": "Social Network",
"website": "https://odoo-community.org/",
"author": "Odoo Community Association (OCA)",
Expand All @@ -12,7 +12,4 @@
"depends": [
"mail",
],
"data": [
'views/mail_notification_view.xml'
]
}
1 change: 1 addition & 0 deletions mail_debrand/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_thread
41 changes: 41 additions & 0 deletions mail_debrand/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import lxml.html
import re
from odoo import _, api, models


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

@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 = lxml.html.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 lxml.html.tostring(root)

@api.model
def _replace_local_links(self, html, base_url=None):
if not isinstance(html, str):
html = html.decode("utf-8")
html = self._debrand_body(html)
return super()._replace_local_links(html, base_url)
1 change: 1 addition & 0 deletions mail_debrand/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_mail_debrand
25 changes: 25 additions & 0 deletions mail_debrand/tests/test_mail_debrand.py
Original file line number Diff line number Diff line change
@@ -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.thread"]._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.thread"]._debrand_body(self.paynow_arch)
self.assertNotIn(b'Powered by', res)