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.

87 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 x620 <https://github.com/x620>
  3. # Copyright 2016 manawi <https://github.com/manawi>
  4. # Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
  5. # Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
  6. # License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
  7. from odoo import models, fields, api
  8. class MailComposeMessage(models.TransientModel):
  9. _inherit = 'mail.compose.message'
  10. is_private = fields.Boolean(string='Send Internal Message')
  11. def get_internal_users_ids(self):
  12. internal_users_ids = self.env['res.users'].search([('share', '=', False)]).ids
  13. return internal_users_ids
  14. @api.multi
  15. def send_mail(self, auto_commit=False):
  16. for w in self:
  17. w.is_log = True if w.is_private else w.is_log
  18. super(MailComposeMessage, self).send_mail(auto_commit=False)
  19. class MailMessage(models.Model):
  20. _inherit = 'mail.message'
  21. @api.multi
  22. def _notify(self, force_send=False, send_after_commit=True, user_signature=True):
  23. self_sudo = self.sudo()
  24. if 'is_private' not in self_sudo._context or not self_sudo._context['is_private']:
  25. super(MailMessage, self)._notify(force_send, send_after_commit, user_signature)
  26. else:
  27. self._notify_mail_private(force_send, send_after_commit, user_signature)
  28. @api.multi
  29. def _notify_mail_private(self, force_send=False, send_after_commit=True, user_signature=True):
  30. """ The method was partially copied from Odoo.
  31. In the current method, the way of getting channels for a private message is changed.
  32. """
  33. # have a sudoed copy to manipulate partners (public can go here with
  34. # website modules like forum / blog / ...
  35. # TDE CHECK: add partners / channels as arguments to be able to notify a message with / without computation ??
  36. self.ensure_one() # tde: not sure, just for testinh, will see
  37. partners = self.env['res.partner'] | self.partner_ids
  38. channels = self.env['mail.channel'] | self.channel_ids
  39. # update message, with maybe custom values
  40. message_values = {
  41. 'channel_ids': [(6, 0, channels.ids)],
  42. 'needaction_partner_ids': [(6, 0, partners.ids)]
  43. }
  44. if self.model and self.res_id and hasattr(self.env[self.model], 'message_get_message_notify_values'):
  45. message_values.update(
  46. self.env[self.model].browse(self.res_id).message_get_message_notify_values(self, message_values))
  47. self.write(message_values)
  48. # notify partners and channels
  49. partners._notify(self, force_send=force_send, send_after_commit=send_after_commit,
  50. user_signature=user_signature)
  51. channels._notify(self)
  52. # Discard cache, because child / parent allow reading and therefore
  53. # change access rights.
  54. if self.parent_id:
  55. self.parent_id.invalidate_cache()
  56. return True
  57. class MailThread(models.AbstractModel):
  58. _inherit = 'mail.thread'
  59. @api.multi
  60. @api.returns('self', lambda value: value.id)
  61. def message_post(self, body='', subject=None, message_type='notification',
  62. subtype=None, parent_id=False, attachments=None,
  63. content_subtype='html', **kwargs):
  64. if 'channel_ids' in kwargs:
  65. kwargs['channel_ids'] = [(4, pid) for pid in kwargs['channel_ids']]
  66. return super(MailThread, self).message_post(body, subject, message_type,
  67. subtype, parent_id, attachments,
  68. content_subtype, **kwargs)