+ # we want to set a parent: force to set the parent_id to the oldest ancestor, to avoid having more than 1 level of thread
+ elif parent_id:
+ message_ids = mail_message.search(cr, SUPERUSER_ID, [('id', '=', parent_id), ('parent_id', '!=', False)], context=context)
+ _counter, _counter_max = 0, 200
+ while (message_ids and (_counter <= _counter_max)):
+ parent_id = message_ids[0]
+ message_ids = mail_message.search(cr, SUPERUSER_ID, [('id', '=', parent_id), ('parent_id', '!=', False)], context=context)
+ _counter += 1