Merge PR #914 into 15.0

Signed-off-by yajo
This commit is contained in:
OCA-git-bot 2022-05-31 09:43:40 +00:00
commit 215493331c

View File

@ -26,21 +26,12 @@ class MailRenderMixin(models.AbstractModel):
# We don't want to change what was explicitly added in the message body, # We don't want to change what was explicitly added in the message body,
# so we will only change what is before and after it. # so we will only change what is before and after it.
if to_keep: if to_keep:
to_change = value.split(to_keep) value = value.replace(to_keep, "<body_msg></body_msg>")
else: tree = html.fromstring(value)
to_change = [value]
to_keep = ""
new_parts = []
for part in to_change:
tree = html.fromstring(part)
if tree is None:
new_parts.append(part)
continue
odoo_anchors = tree.xpath('//a[contains(@href,"odoo.com")]') odoo_anchors = tree.xpath('//a[contains(@href,"odoo.com")]')
for elem in odoo_anchors: for elem in odoo_anchors:
parent = elem.getparent() parent = elem.getparent()
previous = elem.getprevious() previous = elem.getprevious()
if remove_before and not remove_parent and previous is not None: if remove_before and not remove_parent and previous is not None:
# remove 'using' that is before <a and after </span> # remove 'using' that is before <a and after </span>
previous.tail = "" previous.tail = ""
@ -52,11 +43,11 @@ class MailRenderMixin(models.AbstractModel):
parent.getparent().remove(parent) parent.getparent().remove(parent)
else: else:
parent.remove(elem) parent.remove(elem)
part = etree.tostring( value = etree.tostring(
tree, pretty_print=True, method="html", encoding="unicode" tree, pretty_print=True, method="html", encoding="unicode"
) )
new_parts.append(part) if to_keep:
value = str(to_keep).join(new_parts) value = value.replace("<body_msg></body_msg>", to_keep)
return value return value
@api.model @api.model