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.

68 lines
2.9 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. internal_ids = self.get_internal_users_ids()
  18. recipient_ids = [r.partner_id for r in follower_ids if r.partner_id]
  19. # channel_ids = [c.channel_id for c in follower_ids if c.channel_id]
  20. for recipient in recipient_ids:
  21. result.append({
  22. 'checked': recipient.user_ids.id in internal_ids,
  23. 'partner_id': recipient.id,
  24. 'full_name': recipient.name,
  25. 'name': recipient.name,
  26. 'email_address': recipient.email,
  27. 'reason': 'Recipient'
  28. })
  29. # for channel in channel_ids:
  30. # result.append({
  31. # 'checked': True,
  32. # 'channel_id': channel.id,
  33. # 'full_name': channel,
  34. # 'name': '# '+channel.name,
  35. # 'reason': 'Channel',
  36. # })
  37. return result
  38. @api.multi
  39. def _notify(self, record, msg_vals, force_send=False, send_after_commit=True, model_description=False, mail_auto_delete=True):
  40. self_sudo = self.sudo()
  41. msg_vals = msg_vals if msg_vals else {}
  42. if 'is_private' not in self_sudo._context or not self_sudo._context['is_private']:
  43. return super(MailMessage, self)._notify(record, msg_vals, force_send, send_after_commit, model_description, mail_auto_delete)
  44. else:
  45. rdata = self._notify_compute_internal_recipients(record, msg_vals)
  46. return self._notify_recipients(rdata, record, msg_vals, force_send, send_after_commit, model_description, mail_auto_delete)
  47. @api.multi
  48. def _notify_compute_internal_recipients(self, record, msg_vals):
  49. recipient_data = super(MailMessage, self)._notify_compute_recipients(record, msg_vals)
  50. pids = [x[1] for x in msg_vals.get('partner_ids')] if 'partner_ids' in msg_vals else self.sudo().partner_ids.ids
  51. recipient_data['partners'] = [i for i in recipient_data['partners'] if i['id'] in pids]
  52. return recipient_data
  53. def get_internal_users_ids(self):
  54. internal_users_ids = self.env['res.users'].search([('share', '=', False)]).ids
  55. return internal_users_ids