From 7f6b13b66031bd8905445ce98c8e9b108d08ff4b Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Mon, 15 Mar 2021 18:44:13 +0000 Subject: [PATCH] [FIX] mail_debrand: tolerate binary inputs, solve etree FutureWarning --- mail_debrand/models/mail_render_mixinANDmail_mail.py | 9 ++++++--- mail_debrand/tests/test_mail_debrand.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mail_debrand/models/mail_render_mixinANDmail_mail.py b/mail_debrand/models/mail_render_mixinANDmail_mail.py index 61f67e7..d62f2a8 100644 --- a/mail_debrand/models/mail_render_mixinANDmail_mail.py +++ b/mail_debrand/models/mail_render_mixinANDmail_mail.py @@ -15,17 +15,20 @@ class MailRenderMixin(models.AbstractModel): def remove_href_odoo(self, value, remove_parent=True, remove_before=False): if len(value) < 20: return value + # value can be bytes type; ensure we get a proper string + if type(value) is bytes: + value = value.decode() has_odoo_link = re.search(r" bytes_text = etree.tostring( previous, pretty_print=True, method="html" @@ -33,7 +36,7 @@ class MailRenderMixin(models.AbstractModel): only_what_is_in_tags = bytes_text[: bytes_text.rfind(b">") + 1] data_formatted = html.fromstring(only_what_is_in_tags) parent.replace(previous, data_formatted) - if len(parent.getparent()) and remove_parent: + if remove_parent and len(parent.getparent()): # anchor