From b3ad28816f563b1e05181bf43cecf0bfc9badec1 Mon Sep 17 00:00:00 2001 From: "Cuong, Nguyen Minh Tran Manh" Date: Fri, 6 Oct 2023 19:16:20 +0700 Subject: [PATCH] [16.0][IMP] mail_debrand: Add remove_href_odoo_special_case When rendering the template, the remove_href_odoo function will remove the parent of the 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 --- mail_debrand/models/mail_render_mixin.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mail_debrand/models/mail_render_mixin.py b/mail_debrand/models/mail_render_mixin.py index c9cb74a4fe..452c0b1e9a 100644 --- a/mail_debrand/models/mail_render_mixin.py +++ b/mail_debrand/models/mail_render_mixin.py @@ -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 @@ -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