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.

102 lines
3.4 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 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. 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. {
  23. "checked": recipient.user_ids.id in internal_ids,
  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. def _notify(
  41. self,
  42. record,
  43. msg_vals,
  44. force_send=False,
  45. send_after_commit=True,
  46. model_description=False,
  47. mail_auto_delete=True,
  48. ):
  49. self_sudo = self.sudo()
  50. msg_vals = msg_vals if msg_vals else {}
  51. if (
  52. "is_private" not in self_sudo._context
  53. or not self_sudo._context["is_private"]
  54. ):
  55. return super(MailMessage, self)._notify(
  56. record,
  57. msg_vals,
  58. force_send,
  59. send_after_commit,
  60. model_description,
  61. mail_auto_delete,
  62. )
  63. else:
  64. rdata = self._notify_compute_internal_recipients(record, msg_vals)
  65. return self._notify_recipients(
  66. rdata,
  67. record,
  68. msg_vals,
  69. force_send,
  70. send_after_commit,
  71. model_description,
  72. mail_auto_delete,
  73. )
  74. def _notify_compute_internal_recipients(self, record, msg_vals):
  75. recipient_data = super(MailMessage, self)._notify_compute_recipients(
  76. record, msg_vals
  77. )
  78. pids = (
  79. [x[1] for x in msg_vals.get("partner_ids")]
  80. if "partner_ids" in msg_vals
  81. else self.sudo().partner_ids.ids
  82. )
  83. recipient_data["partners"] = [
  84. i for i in recipient_data["partners"] if i["id"] in pids
  85. ]
  86. return recipient_data
  87. def get_internal_users_ids(self):
  88. internal_users_ids = self.env["res.users"].search([("share", "=", False)]).ids
  89. return internal_users_ids