From c6207a38b6947f66762da45a8fecc5c2c24ff815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 29 Oct 2020 13:58:34 +0000 Subject: [PATCH] [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) --- addons/mail/models/mail_thread.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index a013c640779..c92584ab9e8 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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 # ------------------------------------------------------