From 3e36e6c88fdb52573f963cb8a0ddf37ee866bc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 25 Oct 2012 17:42:15 +0200 Subject: [PATCH] [FIX] mail: fixed ancestor search in message_post. bzr revid: tde@openerp.com-20121025154215-ue4tpe3cua7491no --- addons/mail/mail_thread.py | 11 ++++++----- addons/mail/tests/test_mail.py | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index cc9d7d3627f..7ce3eb3afd8 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -679,11 +679,12 @@ class mail_thread(osv.AbstractModel): # 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 + if message_ids: + _counter, _counter_max = 0, 200 + message = mail_message.browse(cr, SUPERUSER_ID, message_ids[0], context=context) + while (message.parent_id and (_counter <= _counter_max)): + message = message.parent_id + parent_id = message.id values = kwargs values.update({ diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index b83f55e3973..a1e53c4ec68 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -436,6 +436,11 @@ class test_mail(TestMailMockups): self.assertIn((attach.name, attach.datas.decode('base64')), _attachments, 'mail.message attachment name / data incorrect') + # 3. Reply to the last message, check that its parent will be the first message + msg_id3 = self.mail_group.message_post(cr, uid, self.group_pigs_id, body='Test', parent_id=msg_id2) + message = self.mail_message.browse(cr, uid, msg_id3) + self.assertEqual(message.parent_id.id, msg_id, 'message_post did not flatten the thread structure') + def test_25_message_compose_wizard(self): """ Tests designed for the mail.compose.message wizard. """ cr, uid, user_admin, group_pigs = self.cr, self.uid, self.user_admin, self.group_pigs