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 b3ad288
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 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,26 @@
class MailRenderMixin(models.AbstractModel):
_inherit = "mail.render.mixin"

def remove_href_odoo_special_case(self, elem):
parent = elem.getparent()
previous_elem = elem.getprevious()
# auth_signup.set_password_email
if previous_elem is not None and previous_elem.tag == "br":
head_msg = "Have a look at the"
tail_msg = "to discover the tool."
if (
previous_elem.tail
and head_msg in previous_elem.tail
and elem.tail
and tail_msg in elem.tail
):
previous_elem.tail = previous_elem.tail.replace(head_msg, "")
elem.tail = elem.tail.replace(tail_msg, "")
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 +55,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 b3ad288

Please sign in to comment.