Skip to content

Commit

Permalink
[16.0][IMP] mail_debrand: Add remove_href_odoo_special_case
Browse files Browse the repository at this point in the history
When rendering the template, the remove_href_odoo function will remove the parent of the <a> element which has 'odoo.com' in href.
There is a problem with mail.template "New Portal Signup", the parent element is almost the whole content hence most of the content will be removed.

remove_href_odoo_special_case() is added to handle this special case.t push
  • Loading branch information
cuongnmtm committed Oct 6, 2023
1 parent f66dbf1 commit f50749e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mail_debrand/models/mail_render_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@
class MailRenderMixin(models.AbstractModel):
_inherit = "mail.render.mixin"

def remove_href_odoo_special_case(self, elem):
parent = elem.getparent()
previous_elem = elem.getprevious()
if previous_elem.tag == "br":
if (
previous_elem.tail
and "Have a look at the " in previous_elem.tail
and elem.tail
and " to discover the tool." in elem.tail
):
previous_elem.tail = previous_elem.tail.replace(
"Have a look at the ", ""
)
elem.tail = elem.tail.replace(" to discover the tool.", "")
parent.remove(previous_elem)
parent.remove(elem)
return True
return False

def remove_href_odoo(self, value, remove_parent=True, to_keep=None):
if len(value) < 20:
return value
Expand All @@ -35,6 +54,8 @@ def remove_href_odoo(self, value, remove_parent=True, to_keep=None):
tree = html.fromstring(value)
odoo_anchors = tree.xpath('//a[contains(@href,"odoo.com")]')
for elem in odoo_anchors:
if self.remove_href_odoo_special_case(elem):
continue
parent = elem.getparent()
if remove_parent and parent.getparent() is not None:
# anchor <a href odoo has a parent powered by that must be removed
Expand Down

0 comments on commit f50749e

Please sign in to comment.