[IMP] mail: allow to specify a new parent when using message_change_thread

Purpose of this commit is to allow to attach moved messages from a thread
to a new parent. This allows notably to keep references if message
hierarchy is not kept as it is.

LINKS

Task ID-2083049
COM PR odoo/odoo#49129
ENT PR odoo/enterprise#9715
UPG PR odoo/upgrade#1883

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2020-11-05 08:12:21 +00:00
parent abe68c9fb8
commit c6207a38b6
+9 -3
View File
@@ -457,7 +457,7 @@ class MailThread(models.AbstractModel):
# WRAPPERS AND TOOLS
# ------------------------------------------------------
def message_change_thread(self, new_thread):
def message_change_thread(self, new_thread, new_parent_message=False):
"""
Transfer the list of the mail thread messages from an model to another
@@ -487,8 +487,14 @@ class MailThread(models.AbstractModel):
('subtype_id', '!=', subtype_comment)])
# update the messages
msg_comment.write({"res_id": new_thread.id, "model": new_thread._name})
msg_not_comment.write({"res_id": new_thread.id, "model": new_thread._name, "subtype_id": None})
msg_vals = {"res_id": new_thread.id, "model": new_thread._name}
if new_parent_message:
msg_vals["parent_id"] = new_parent_message.id
msg_comment.write(msg_vals)
# other than comment: reset subtype
msg_vals["subtype_id"] = None
msg_not_comment.write(msg_vals)
return True
# ------------------------------------------------------