From af53ccf57c48758d74cb96c96ba0c109cb4b6618 Mon Sep 17 00:00:00 2001
From: miguels73 <55379877+miguels73@users.noreply.github.com>
Date: Mon, 23 May 2022 18:29:08 +0200
Subject: [PATCH] [FIX] mail_debrand: remove_href_odoo function
- FIX bug when split email message by `to_keep` parameter. When the html code is split, it is broken. As a result of this, when it use `fromstring`,
it try to fix this by closing tags.
Example about fixed functionality:
message:
`
`
Split messsage inside `remove_href_odoo` function:
part[0]
`
`
-----------------
Result when join by `to_keep`
`
`
---
mail_debrand/models/mail_render_mixin.py | 49 ++++++++++--------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/mail_debrand/models/mail_render_mixin.py b/mail_debrand/models/mail_render_mixin.py
index 3123de282..dbedcd069 100644
--- a/mail_debrand/models/mail_render_mixin.py
+++ b/mail_debrand/models/mail_render_mixin.py
@@ -26,37 +26,28 @@ class MailRenderMixin(models.AbstractModel):
# 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.
if to_keep:
- to_change = value.split(to_keep)
- else:
- 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")]')
- 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 ")
+ 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