[FIX] mail_message: fixed messages that could be present several times in the result structure of message_read.

bzr revid: tde@openerp.com-20120828131311-1z27oxmgcej9qf4m
This commit is contained in:
Thibault Delavallée 2012-08-28 15:13:11 +02:00
parent d7a6f580d8
commit 720ddfd5c8
3 changed files with 20 additions and 14 deletions

View File

@ -37,7 +37,7 @@
</record>
<record id="action_view_notifications" model="ir.actions.act_window">
<field name="name">Pushed notif</field>
<field name="name">Notifications</field>
<field name="res_model">mail.notification</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>

View File

@ -173,12 +173,6 @@ class mail_message(osv.Model):
'child_ids': [],
}
def _debug_print_tree(self, tree, prefix=''):
for elem in tree:
print '%s%s' % (prefix, elem['id'])
if elem['child_ids']:
self._debug_print_tree(elem['child_ids'], prefix+'-')
def message_read(self, cr, uid, ids=False, domain=[], thread_level=0, limit=None, context=None):
"""
If IDS are provided, fetch these records, otherwise use the domain to
@ -208,9 +202,10 @@ class mail_message(osv.Model):
record_parent = tree[msg.parent_id.id]
else:
record_parent = self._message_dict_get(cr, uid, msg.parent_id, context=context)
if msg.parent_id.parent_id and msg.parent_id.id not in tree:
if msg.parent_id.parent_id:
tree[msg.parent_id.id] = record_parent
record_parent['child_ids'].append(record)
if record['id'] not in [x['id'] for x in record_parent['child_ids']]:
record_parent['child_ids'].append(record)
record = record_parent
msg = msg.parent_id
if msg.id not in tree:
@ -224,8 +219,6 @@ class mail_message(osv.Model):
'thread_level': thread_level # should be improve accodting to level of records
})
break
# TDE temp: debug print
# self._debug_print_tree(result)
return result
@ -338,6 +331,6 @@ class mail_notification(osv.Model):
def set_message_read(self, cr, uid, msg_id, context=None):
partner_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id
notif_ids = self.search(cr, uid, [('partner_id', '=', partner_id), ('message_id', '=', msg_id)], context=context)
return self.write(cr, uid, notif_ids, {'read': True})
return self.write(cr, uid, notif_ids, {'read': True}, context=context)

View File

@ -338,12 +338,25 @@ class test_mail(common.TransactionCase):
# Second try: read with thread_level 1
res = self.mail_message.message_read(cr, uid, ids=False, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], thread_level=1)
# print res
# print '----'
# self.mail_message._debug_print_tree(res)
# print '----'
self.assertTrue(len(res) == 2, 'Incorrect number of child in message_read')
self.assertTrue(len(res[0]['child_ids']) == 2, 'Incorrect number of child in message_read')
self.assertTrue(len(res[0]['child_ids'][0]['child_ids']) == 1, 'Incorrect number of child in message_read')
# trees = self.mail_message.message_read_tree_flatten_main(cr, uid, res, thread_level=0)
# print trees
# print '----'
# self.mail_message._debug_print_tree(trees)
# print '----'
res = self.mail_message.message_read(cr, uid, ids=False, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], thread_level=1)
# trees = self.mail_message.message_read_tree_flatten_main(cr, uid, res, thread_level=1)
# print '----'
# self.mail_message._debug_print_tree(trees)
# print '----'
self.assertTrue(len(res) == 3, 'Incorrect number of child in message_read')
def test_40_needaction(self):
""" Tests for mail.message needaction. """