[FIX] mail: mass mailing now does not push to followers; only to specific recipients. Improved tests for this update.

bzr revid: tde@openerp.com-20130320084040-pcgzy068z0oph298
This commit is contained in:
Thibault Delavallée 2013-03-20 09:40:40 +01:00
parent 82b3e9b5fd
commit 2c497fab50
2 changed files with 19 additions and 8 deletions

View File

@ -524,7 +524,7 @@ class test_mail(TestMailBase):
# 1. mass_mail on pigs and bird
compose_id = mail_compose.create(cr, uid,
{'subject': _subject, 'body': '${object.description}'},
{'subject': _subject, 'body': '${object.description}', 'partner_ids': [(4, p_c_id), (4, p_d_id)]},
{'default_composition_mode': 'mass_mail', 'default_model': 'mail.group', 'default_res_id': False,
'active_ids': [self.group_pigs_id, group_bird_id]})
compose = mail_compose.browse(cr, uid, compose_id)
@ -540,11 +540,19 @@ class test_mail(TestMailBase):
test_msg_ids = self.mail_message.search(cr, uid, [], limit=2)
self.assertIn(message1.id, test_msg_ids, 'Pigs did not receive its mass mailing message')
self.assertIn(message2.id, test_msg_ids, 'Bird did not receive its mass mailing message')
# Test: mail.message: subject, body
self.assertEqual(message1.subject, _subject, 'mail.message subject incorrect')
self.assertEqual(message1.body, '<p>%s</p>' % group_pigs.description, 'mail.message body incorrect')
self.assertEqual(message2.subject, _subject, 'mail.message subject incorrect')
self.assertEqual(message2.body, '<p>%s</p>' % group_bird.description, 'mail.message body incorrect')
# Test: mail.message: subject, body, subtype, notified partners (nobody + specific recipients)
self.assertEqual(message1.subject, _subject,
'message_post: mail.message in mass mail subject incorrect')
self.assertEqual(message1.body, '<p>%s</p>' % group_pigs.description,
'message_post: mail.message in mass mail body incorrect')
self.assertEqual(set([p.id for p in message1.notified_partner_ids]), set([p_c_id, p_d_id]),
'message_post: mail.message in mass mail incorrect notified partners')
self.assertEqual(message2.subject, _subject,
'message_post: mail.message in mass mail subject incorrect')
self.assertEqual(message2.body, '<p>%s</p>' % group_bird.description,
'message_post: mail.message in mass mail body incorrect')
self.assertEqual(set([p.id for p in message2.notified_partner_ids]), set([p_c_id, p_d_id]),
'message_post: mail.message in mass mail incorrect notified partners')
def test_30_needaction(self):
""" Tests for mail.message needaction. """

View File

@ -218,9 +218,12 @@ class mail_compose_message(osv.TransientModel):
post_values.update(email_dict)
# post the message
subtype = 'mail.mt_comment'
if is_log:
if is_log or mass_mail_mode:
subtype = False
active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
# mass_mailing: notify specific partners, because subtype was False, and no-one was notified
if mass_mail_mode and post_values['partner_ids']:
self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
return {'type': 'ir.actions.act_window_close'}