parameters: (self, new_thread, new_parent_message=False)
return_statement: return True
docstring: Transfer the list of the mail thread messages from an model to another
  
          :param id : the old res_id of the mail.message
          :param new_res_id : the new res_id of the mail.message
          :param new_model : the name of the new model of the mail.message
  
          Example :   my_lead.message_change_thread(my_project_task)
                      will transfer the context of the thread of my_lead to my_project_task
docstring_summary: Transfer the list of the mail thread messages from an model to another
docstring_tokens: Transfer the list of the mail thread messages from an model to another
function: def message_change_thread(self, new_thread, new_parent_message=False):
          """
          Transfer the list of the mail thread messages from an model to another
  
          :param id : the old res_id of the mail.message
          :param new_res_id : the new res_id of the mail.message
          :param new_model : the name of the new model of the mail.message
  
          Example :   my_lead.message_change_thread(my_project_task)
                      will transfer the context of the thread of my_lead to my_project_task
          """
          self.ensure_one()
          # get the subtype of the comment Message
          subtype_comment = self.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment')
  
          # get the ids of the comment and not-comment of the thread
          # TDE check: sudo on mail.message, to be sure all messages are moved ?
          MailMessage = self.env['mail.message']
          msg_comment = MailMessage.search([
              ('model', '=', self._name),
              ('res_id', '=', self.id),
              ('message_type', '!=', 'user_notification'),
              ('subtype_id', '=', subtype_comment)])
          msg_not_comment = MailMessage.search([
              ('model', '=', self._name),
              ('res_id', '=', self.id),
              ('message_type', '!=', 'user_notification'),
              ('subtype_id', '!=', subtype_comment)])
  
          # update the messages
          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
function_tokens: def message_change_thread ( self , new_thread , new_parent_message = False ) : self . ensure_one ( ) # get the subtype of the comment Message subtype_comment = self . env [ 'ir.model.data' ] . _xmlid_to_res_id ( 'mail.mt_comment' ) # get the ids of the comment and not-comment of the thread # TDE check: sudo on mail.message, to be sure all messages are moved ? MailMessage = self . env [ 'mail.message' ] msg_comment = MailMessage . search ( [ ( 'model' , '=' , self . _name ) , ( 'res_id' , '=' , self . id ) , ( 'message_type' , '!=' , 'user_notification' ) , ( 'subtype_id' , '=' , subtype_comment ) ] ) msg_not_comment = MailMessage . search ( [ ( 'model' , '=' , self . _name ) , ( 'res_id' , '=' , self . id ) , ( 'message_type' , '!=' , 'user_notification' ) , ( 'subtype_id' , '!=' , subtype_comment ) ] ) # update the messages 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