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

  1. # Copyright 2016 x620 <https://github.com/x620>
  2. # Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
  3. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  4. # Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
  5. # License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
  6. from odoo import models, fields, api
  7. class MailComposeMessage(models.TransientModel):
  8. _inherit = 'mail.compose.message'
  9. is_private = fields.Boolean(string='Send Internal Message')
  10. class MailMessage(models.Model):
  11. _inherit = 'mail.message'
  12. is_private = fields.Boolean(string='Send Internal Message')
  13. def send_recepients_for_internal_message(self, model, domain):
  14. result = []
  15. default_resource = self.env[model].search(domain)
  16. follower_ids = default_resource.message_follower_ids
  17. recipient_ids = [r.partner_id for r in follower_ids if r.partner_id]
  18. # channel_ids = [c.channel_id for c in follower_ids if c.channel_id]
  19. for recipient in recipient_ids:
  20. result.append({
  21. 'checked': len(recipient.user_ids) > 0,
  22. 'partner_id': recipient.id,
  23. 'full_name': recipient.name,
  24. 'name': recipient.name,
  25. 'email_address': recipient.email,
  26. 'reason': 'Recipient'
  27. })
  28. # for channel in channel_ids:
  29. # result.append({
  30. # 'checked': True,
  31. # 'channel_id': channel.id,
  32. # 'full_name': channel,
  33. # 'name': '# '+channel.name,
  34. # 'reason': 'Channel',
  35. # })
  36. return result
  37. @api.multi
  38. def _notify(self, record, msg_vals, force_send=False, send_after_commit=True, model_description=False, mail_auto_delete=True):
  39. self_sudo = self.sudo()
  40. msg_vals = msg_vals if msg_vals else {}
  41. if 'is_private' not in self_sudo._context or not self_sudo._context['is_private']:
  42. return super(MailMessage, self)._notify(record, msg_vals, force_send, send_after_commit, model_description, mail_auto_delete)
  43. else:
  44. rdata = self._notify_compute_internal_recipients(record, msg_vals)
  45. return self._notify_recipients(rdata, record, msg_vals, force_send, send_after_commit, model_description, mail_auto_delete)
  46. @api.multi
  47. def _notify_compute_internal_recipients(self, record, msg_vals):
  48. recipient_data = super(MailMessage, self)._notify_compute_recipients(record, msg_vals)
  49. pids = [x[1] for x in msg_vals.get('partner_ids')] if 'partner_ids' in msg_vals else self.sudo().partner_ids.ids
  50. recipient_data['partners'] = [i for i in recipient_data['partners'] if i['id'] in pids]
  51. return recipient_data