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.4 KiB

  1. # Copyright 2017 Tecnativa - Pedro M. Baeza
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import re
  4. from odoo import _, api, models
  5. class MailTemplate(models.Model):
  6. _inherit = 'mail.template'
  7. @api.multi
  8. def generate_email(self, res_ids, fields=None):
  9. mail_template = self.env.ref(
  10. 'mail.mail_template_data_notification_email_default'
  11. )
  12. if self == mail_template:
  13. obj = self.with_context(mail_debrand=True)
  14. else:
  15. obj = self
  16. return super(MailTemplate, obj).generate_email(res_ids, fields=fields)
  17. @api.model
  18. def _debrand_body(self, body):
  19. using_word = _('using')
  20. odoo_word = _('Odoo')
  21. return re.sub(
  22. using_word + "(.*)[\r\n]*(.*)>" + odoo_word + r"</a>", "", body,
  23. )
  24. @api.model
  25. def render_template(self, template_txt, model, res_ids,
  26. post_process=False):
  27. res = super(MailTemplate, self).render_template(
  28. template_txt, model, res_ids, post_process=post_process,
  29. )
  30. if post_process and self.env.context.get('mail_debrand'):
  31. if isinstance(res, str):
  32. res = self._debrand_body(res)
  33. else:
  34. for res_id, body in res.items():
  35. res[res_id] = self._debrand_body(body)
  36. return res