|
@ -12,6 +12,29 @@ class MailComposeMessage(models.TransientModel): |
|
|
is_private = fields.Boolean(string="Send Internal Message") |
|
|
is_private = fields.Boolean(string="Send Internal Message") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailThread(models.AbstractModel): |
|
|
|
|
|
_inherit = "mail.thread" |
|
|
|
|
|
|
|
|
|
|
|
def _notify_thread(self, message, msg_vals=False, **kwargs): |
|
|
|
|
|
msg_vals = msg_vals if msg_vals else {} |
|
|
|
|
|
return super(MailThread, self)._notify_thread(message, msg_vals) |
|
|
|
|
|
|
|
|
|
|
|
def _notify_compute_recipients(self, message, msg_vals): |
|
|
|
|
|
recipient_data = super(MailThread, self)._notify_compute_recipients( |
|
|
|
|
|
message, msg_vals |
|
|
|
|
|
) |
|
|
|
|
|
if "is_private" in message._context: |
|
|
|
|
|
pids = ( |
|
|
|
|
|
[x for x in msg_vals.get("partner_ids")] |
|
|
|
|
|
if "partner_ids" in msg_vals |
|
|
|
|
|
else self.sudo().partner_ids.ids |
|
|
|
|
|
) |
|
|
|
|
|
recipient_data["partners"] = [ |
|
|
|
|
|
i for i in recipient_data["partners"] if i["id"] in pids |
|
|
|
|
|
] |
|
|
|
|
|
return recipient_data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MailMessage(models.Model): |
|
|
class MailMessage(models.Model): |
|
|
_inherit = "mail.message" |
|
|
_inherit = "mail.message" |
|
|
|
|
|
|
|
@ -24,7 +47,6 @@ class MailMessage(models.Model): |
|
|
internal_ids = self.get_internal_users_ids() |
|
|
internal_ids = self.get_internal_users_ids() |
|
|
|
|
|
|
|
|
recipient_ids = [r.partner_id for r in follower_ids if r.partner_id] |
|
|
recipient_ids = [r.partner_id for r in follower_ids if r.partner_id] |
|
|
# channel_ids = [c.channel_id for c in follower_ids if c.channel_id] |
|
|
|
|
|
|
|
|
|
|
|
for recipient in recipient_ids: |
|
|
for recipient in recipient_ids: |
|
|
result.append( |
|
|
result.append( |
|
@ -38,65 +60,8 @@ class MailMessage(models.Model): |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# for channel in channel_ids: |
|
|
|
|
|
# result.append({ |
|
|
|
|
|
# 'checked': True, |
|
|
|
|
|
# 'channel_id': channel.id, |
|
|
|
|
|
# 'full_name': channel, |
|
|
|
|
|
# 'name': '# '+channel.name, |
|
|
|
|
|
# 'reason': 'Channel', |
|
|
|
|
|
# }) |
|
|
|
|
|
return result |
|
|
return result |
|
|
|
|
|
|
|
|
def _notify( |
|
|
|
|
|
self, |
|
|
|
|
|
record, |
|
|
|
|
|
msg_vals, |
|
|
|
|
|
force_send=False, |
|
|
|
|
|
send_after_commit=True, |
|
|
|
|
|
model_description=False, |
|
|
|
|
|
mail_auto_delete=True, |
|
|
|
|
|
): |
|
|
|
|
|
self_sudo = self.sudo() |
|
|
|
|
|
msg_vals = msg_vals if msg_vals else {} |
|
|
|
|
|
if ( |
|
|
|
|
|
"is_private" not in self_sudo._context |
|
|
|
|
|
or not self_sudo._context["is_private"] |
|
|
|
|
|
): |
|
|
|
|
|
return super(MailMessage, self)._notify( |
|
|
|
|
|
record, |
|
|
|
|
|
msg_vals, |
|
|
|
|
|
force_send, |
|
|
|
|
|
send_after_commit, |
|
|
|
|
|
model_description, |
|
|
|
|
|
mail_auto_delete, |
|
|
|
|
|
) |
|
|
|
|
|
else: |
|
|
|
|
|
rdata = self._notify_compute_internal_recipients(record, msg_vals) |
|
|
|
|
|
return self._notify_recipients( |
|
|
|
|
|
rdata, |
|
|
|
|
|
record, |
|
|
|
|
|
msg_vals, |
|
|
|
|
|
force_send, |
|
|
|
|
|
send_after_commit, |
|
|
|
|
|
model_description, |
|
|
|
|
|
mail_auto_delete, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def _notify_compute_internal_recipients(self, record, msg_vals): |
|
|
|
|
|
recipient_data = super(MailMessage, self)._notify_compute_recipients( |
|
|
|
|
|
record, msg_vals |
|
|
|
|
|
) |
|
|
|
|
|
pids = ( |
|
|
|
|
|
[x[1] for x in msg_vals.get("partner_ids")] |
|
|
|
|
|
if "partner_ids" in msg_vals |
|
|
|
|
|
else self.sudo().partner_ids.ids |
|
|
|
|
|
) |
|
|
|
|
|
recipient_data["partners"] = [ |
|
|
|
|
|
i for i in recipient_data["partners"] if i["id"] in pids |
|
|
|
|
|
] |
|
|
|
|
|
return recipient_data |
|
|
|
|
|
|
|
|
|
|
|
def get_internal_users_ids(self): |
|
|
def get_internal_users_ids(self): |
|
|
internal_users_ids = self.env["res.users"].search([("share", "=", False)]).ids |
|
|
internal_users_ids = self.env["res.users"].search([("share", "=", False)]).ids |
|
|
return internal_users_ids |
|
|
return internal_users_ids |