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.

63 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 ACSONE SA/NV <https://acsone.eu>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api
  5. from openerp import tools
  6. from openerp.tools.translate import _
  7. class MailNotification(models.Model):
  8. _inherit = 'mail.notification'
  9. @api.model
  10. def _get_partner_names(self, partner_ids):
  11. """
  12. :type partner_ids: [integer]
  13. :param partner_ids: ids of the partner followers
  14. :rparam: list of the partner'name that are also a user or having
  15. notify_email attribute not none
  16. """
  17. partners = self.env['res.partner'].browse(partner_ids)
  18. partners_name = [
  19. partner.name for partner in partners if
  20. partner.user_ids or partner.notify_email != 'none'
  21. ]
  22. return partners_name
  23. @api.model
  24. def get_signature_footer(
  25. self, user_id, res_model=None, res_id=None, user_signature=True):
  26. """
  27. Override this method to add name of notified partners into the mail
  28. footer
  29. """
  30. footer = super(MailNotification, self).get_signature_footer(
  31. user_id, res_model=res_model, res_id=res_id,
  32. user_signature=user_signature)
  33. partner_ids = self.env.context.get('partners_to_notify')
  34. if footer and partner_ids:
  35. partners_name = self._get_partner_names(partner_ids)
  36. additional_footer = u'<br /><small>%s%s.</small><br />' %\
  37. (_('Also notified: '),
  38. ', '.join(partners_name))
  39. footer = tools.append_content_to_html(
  40. additional_footer, footer, plaintext=False,
  41. container_tag='div')
  42. return footer
  43. @api.one
  44. def _notify(
  45. self, partners_to_notify=None, force_send=False,
  46. user_signature=True):
  47. ctx = self.env.context.copy()
  48. if not self.env.context.get('mail_notify_noemail'):
  49. ctx.update({
  50. 'partners_to_notify': partners_to_notify,
  51. })
  52. return super(MailNotification, self._model)._notify(
  53. self.env.cr, self.env.uid, self.id,
  54. partners_to_notify=partners_to_notify,
  55. force_send=force_send, user_signature=user_signature, context=ctx)