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.

52 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antiun Ingeniería S.L. - Jairo Llopis
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import _, api, models, tools
  5. class MailNotification(models.Model):
  6. _inherit = "mail.notification"
  7. @api.model
  8. def get_signature_footer(self, user_id, res_model=None, res_id=None,
  9. user_signature=True):
  10. """Generate signature footer only with the chosen parts.
  11. Now, you can set ``skip_signature_user=True`` in the context to remove
  12. the user signature (it's the same as ``user_signature=False``), and
  13. ``skip_signature_company=True`` to remove the company's.
  14. """
  15. user = self.env["res.users"].browse(user_id)
  16. parts = list()
  17. if user_signature and not self.env.context.get("skip_signature_user"):
  18. parts.append(self._get_signature_footer_user(user))
  19. if not self.env.context.get("skip_signature_company"):
  20. parts.append(self._get_signature_footer_company(user))
  21. footer = ""
  22. for part in parts:
  23. footer = tools.append_content_to_html(
  24. footer, part, plaintext=False)
  25. return footer
  26. @api.model
  27. def _get_signature_footer_user(self, user):
  28. """User part of the signature."""
  29. return user.signature if user.signature else "--<br />%s" % user.name
  30. def _get_signature_footer_company(self, user):
  31. """Company part of the signature."""
  32. website = user.company_id.website
  33. if website:
  34. if not website.startswith(('http:', 'https:')):
  35. website = "http://" + website
  36. company = ("<a style='color:inherit' href='%s'>%s</a>" %
  37. (website, user.company_id.name))
  38. else:
  39. company = user.company_id.name
  40. sent_by = _('Sent by %s') % company
  41. return '<br /><small>%s</small>' % sent_by