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.

100 lines
3.3 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 MIT (https://opensource.org/licenses/MIT).
  6. from odoo import api, fields, models
  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. {
  22. "checked": recipient.user_ids.id
  23. and not any(recipient.user_ids.mapped("share")),
  24. "partner_id": recipient.id,
  25. "full_name": recipient.name,
  26. "name": recipient.name,
  27. "email_address": recipient.email,
  28. "reason": "Recipient",
  29. }
  30. )
  31. # for channel in channel_ids:
  32. # result.append({
  33. # 'checked': True,
  34. # 'channel_id': channel.id,
  35. # 'full_name': channel,
  36. # 'name': '# '+channel.name,
  37. # 'reason': 'Channel',
  38. # })
  39. return result
  40. @api.multi
  41. def _notify(
  42. self,
  43. record,
  44. msg_vals,
  45. force_send=False,
  46. send_after_commit=True,
  47. model_description=False,
  48. mail_auto_delete=True,
  49. ):
  50. self_sudo = self.sudo()
  51. msg_vals = msg_vals if msg_vals else {}
  52. if (
  53. "is_private" not in self_sudo._context
  54. or not self_sudo._context["is_private"]
  55. ):
  56. return super(MailMessage, self)._notify(
  57. record,
  58. msg_vals,
  59. force_send,
  60. send_after_commit,
  61. model_description,
  62. mail_auto_delete,
  63. )
  64. else:
  65. rdata = self._notify_compute_internal_recipients(record, msg_vals)
  66. return self._notify_recipients(
  67. rdata,
  68. record,
  69. msg_vals,
  70. force_send=force_send,
  71. send_after_commit=send_after_commit,
  72. model_description=model_description,
  73. mail_auto_delete=mail_auto_delete,
  74. )
  75. @api.multi
  76. def _notify_compute_internal_recipients(self, record, msg_vals):
  77. recipient_data = super(MailMessage, self)._notify_compute_recipients(
  78. record, msg_vals
  79. )
  80. pids = (
  81. [x[1] for x in msg_vals.get("partner_ids")]
  82. if "partner_ids" in msg_vals
  83. else self.sudo().partner_ids.ids
  84. )
  85. recipient_data["partners"] = [
  86. i for i in recipient_data["partners"] if i["id"] in pids
  87. ]
  88. return recipient_data