|
|
@ -11,6 +11,36 @@ class MailComposeMessage(models.TransientModel): |
|
|
|
|
|
|
|
is_private = fields.Boolean(string="Send Internal Message") |
|
|
|
|
|
|
|
class MailThread(models.AbstractModel): |
|
|
|
_inherit = "mail.thread" |
|
|
|
|
|
|
|
def _notify_thread(self, message, msg_vals=False, **kwargs): |
|
|
|
# import wdb;wdb.set_trace() |
|
|
|
self_sudo = self.sudo() |
|
|
|
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): |
|
|
|
_inherit = "mail.message" |
|
|
@ -48,55 +78,6 @@ class MailMessage(models.Model): |
|
|
|
# }) |
|
|
|
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): |
|
|
|
internal_users_ids = self.env["res.users"].search([("share", "=", False)]).ids |
|
|
|
return internal_users_ids |