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.

43 lines
1.4 KiB

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