You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

  1. # Copyright 2019 O4SB - Graeme Gellatly
  2. # Copyright 2019 Tecnativa - Ernesto Tejeda
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from lxml import html as htmltree
  5. import re
  6. from odoo import _, api, models
  7. class MailTemplate(models.Model):
  8. _inherit = "mail.template"
  9. @api.model
  10. def _debrand_body(self, html):
  11. using_word = _('using')
  12. odoo_word = _('Odoo')
  13. html = re.sub(
  14. using_word + "(.*)[\r\n]*(.*)>" + odoo_word + r"</a>", "", html,
  15. )
  16. powered_by = _("Powered by")
  17. if powered_by not in html:
  18. return html
  19. root = htmltree.fromstring(html)
  20. powered_by_elements = root.xpath(
  21. "//*[text()[contains(.,'%s')]]" % powered_by
  22. )
  23. for elem in powered_by_elements:
  24. # make sure it isn't a spurious powered by
  25. if any(
  26. [
  27. "www.odoo.com" in child.get("href", "")
  28. for child in elem.getchildren()
  29. ]
  30. ):
  31. for child in elem.getchildren():
  32. elem.remove(child)
  33. elem.text = None
  34. return htmltree.tostring(root).decode("utf-8")
  35. @api.model
  36. def render_post_process(self, html):
  37. html = super().render_post_process(html)
  38. return self._debrand_body(html)