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.

67 lines
2.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 fields, models
  7. class MailComposeMessage(models.TransientModel):
  8. _inherit = "mail.compose.message"
  9. is_private = fields.Boolean(string="Send Internal Message")
  10. class MailThread(models.AbstractModel):
  11. _inherit = "mail.thread"
  12. def _notify_thread(self, message, msg_vals=False, **kwargs):
  13. msg_vals = msg_vals if msg_vals else {}
  14. return super(MailThread, self)._notify_thread(message, msg_vals)
  15. def _notify_compute_recipients(self, message, msg_vals):
  16. recipient_data = super(MailThread, self)._notify_compute_recipients(
  17. message, msg_vals
  18. )
  19. if "is_private" in message._context:
  20. pids = (
  21. [x for x in msg_vals.get("partner_ids")]
  22. if "partner_ids" in msg_vals
  23. else self.sudo().partner_ids.ids
  24. )
  25. recipient_data["partners"] = [
  26. i for i in recipient_data["partners"] if i["id"] in pids
  27. ]
  28. return recipient_data
  29. class MailMessage(models.Model):
  30. _inherit = "mail.message"
  31. is_private = fields.Boolean(string="Send Internal Message")
  32. def send_recepients_for_internal_message(self, model, domain):
  33. result = []
  34. default_resource = self.env[model].search(domain)
  35. follower_ids = default_resource.message_follower_ids
  36. internal_ids = self.get_internal_users_ids()
  37. recipient_ids = [r.partner_id for r in follower_ids if r.partner_id]
  38. for recipient in recipient_ids:
  39. result.append(
  40. {
  41. "checked": recipient.user_ids.id in internal_ids,
  42. "partner_id": recipient.id,
  43. "full_name": recipient.name,
  44. "name": recipient.name,
  45. "email_address": recipient.email,
  46. "reason": "Recipient",
  47. }
  48. )
  49. return result
  50. def get_internal_users_ids(self):
  51. internal_users_ids = self.env["res.users"].search([("share", "=", False)]).ids
  52. return internal_users_ids