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.

39 lines
1.2 KiB

  1. # Copyright 2017 David BEAL @ Akretion
  2. # Copyright 2019 Camptocamp SA
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, models
  5. try:
  6. from premailer import Premailer
  7. except (ImportError, IOError) as err: # pragma: no cover
  8. import logging
  9. _logger = logging.getLogger(__name__)
  10. _logger.debug(err)
  11. class MailTemplate(models.Model):
  12. _inherit = 'mail.template'
  13. @api.multi
  14. def generate_email(self, res_ids, fields=None):
  15. """Use `premailer` to convert styles to inline styles."""
  16. result = super().generate_email(res_ids, fields=fields)
  17. if isinstance(res_ids, int):
  18. premailer = Premailer(
  19. html=result['body_html'],
  20. **self._get_premailer_options(),
  21. )
  22. result['body_html'] = premailer.transform()
  23. else:
  24. for __, data in result.items():
  25. premailer = Premailer(
  26. html=data['body_html'],
  27. **self._get_premailer_options(),
  28. )
  29. data['body_html'] = premailer.transform()
  30. return result
  31. def _get_premailer_options(self):
  32. return {}