# Copyright 2019 O4SB - Graeme Gellatly
# Copyright 2019 Tecnativa - Ernesto Tejeda
# Copyright 2020 Onestein - Andrea Stirpe
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import re
from lxml import etree, html
from odoo import api, models
class MailRenderMixin(models.AbstractModel):
_inherit = "mail.render.mixin"
def remove_href_odoo(
self, value, remove_parent=True, remove_before=False, to_keep=None
):
if len(value) < 20:
return value
# value can be bytes type; ensure we get a proper string
if type(value) is bytes:
value = value.decode()
has_odoo_link = re.search(r"")
tree = html.fromstring(value)
odoo_anchors = tree.xpath('//a[contains(@href,"odoo.com")]')
for elem in odoo_anchors:
parent = elem.getparent()
previous = elem.getprevious()
if remove_before and not remove_parent and previous is not None:
# remove 'using' that is before
previous.tail = ""
if remove_parent and len(parent.getparent()):
# anchor ", to_keep)
return value
@api.model
def _render_template(
self,
template_src,
model,
res_ids,
engine="qweb_view",
add_context=None,
options=None,
post_process=False,
):
"""replace anything that is with odoo in templates
if is a )""", "
", message
)
return message