[CLEAN] mail: stop doing ugly things with partner_ids values before passing values to mail_message.create().
bzr revid: tde@openerp.com-20130221095906-5rbwnc83mjvpkyhh
This commit is contained in:
+10
-13
@@ -885,7 +885,7 @@ class mail_thread(osv.AbstractModel):
|
||||
mail_message = self.pool.get('mail.message')
|
||||
|
||||
# if we're processing a message directly coming from the gateway, the destination model was
|
||||
# set in the context.
|
||||
# set in the context.
|
||||
model = False
|
||||
if thread_id:
|
||||
model = context.get('thread_model', self._name) if self._name == 'mail.thread' else self._name
|
||||
@@ -940,6 +940,7 @@ class mail_thread(osv.AbstractModel):
|
||||
'parent_id': parent_id,
|
||||
'attachment_ids': attachment_ids,
|
||||
'subtype_id': subtype_id,
|
||||
'partner_ids': [(4, pid) for pid in kwargs.get('partner_ids', [])],
|
||||
})
|
||||
|
||||
# Avoid warnings about non-existing fields
|
||||
@@ -970,25 +971,21 @@ class mail_thread(osv.AbstractModel):
|
||||
partner_ids = set([])
|
||||
if parent_id and self._name == 'mail.thread':
|
||||
parent_message = mail_message_obj.browse(cr, uid, parent_id, context=context)
|
||||
partner_ids |= set([(4, partner.id) for partner in parent_message.partner_ids])
|
||||
if parent_message.author_id.id:
|
||||
partner_ids.add((4, parent_message.author_id.id))
|
||||
partner_ids |= set([partner.id for partner in parent_message.partner_ids])
|
||||
if parent_message.author_id:
|
||||
partner_ids.add(parent_message.author_id.id)
|
||||
|
||||
# 1.A.2: add specified recipients
|
||||
param_partner_ids = set()
|
||||
for item in kwargs.pop('partner_ids', []):
|
||||
if isinstance(item, (list)):
|
||||
param_partner_ids.add((item[0], item[1]))
|
||||
elif isinstance(item, (int, long)):
|
||||
param_partner_ids.add((4, item))
|
||||
if isinstance(item, (list, tuple)):
|
||||
partner_ids.add(item[1])
|
||||
else:
|
||||
param_partner_ids.add(item)
|
||||
partner_ids |= param_partner_ids
|
||||
partner_ids.add(item)
|
||||
|
||||
# 1.A.3: add parameters recipients as follower
|
||||
# TDE FIXME in 7.1: should check whether this comes from email_list or partner_ids
|
||||
if param_partner_ids and self._name != 'mail.thread':
|
||||
self.message_subscribe(cr, uid, [thread_id], [pid[1] for pid in param_partner_ids], context=context)
|
||||
if partner_ids and self._name != 'mail.thread':
|
||||
self.message_subscribe(cr, uid, [thread_id], partner_ids, context=context)
|
||||
|
||||
# 1.B: handle body, message_type and message_subtype
|
||||
if content_subtype == 'plaintext':
|
||||
|
||||
@@ -391,7 +391,7 @@ class test_mail(TestMailBase):
|
||||
# 1. Post a new email comment on Pigs
|
||||
self._init_mock_build_email()
|
||||
msg2_id = self.mail_group.message_post(cr, user_raoul.id, self.group_pigs_id, body=_body2, type='email', subtype='mt_comment',
|
||||
partner_ids=[(6, 0, [p_d_id])], parent_id=msg1_id, attachments=_attachments)
|
||||
partner_ids=[p_d_id], parent_id=msg1_id, attachments=_attachments)
|
||||
message2 = self.mail_message.browse(cr, uid, msg2_id)
|
||||
sent_emails = self._build_email_kwargs_list
|
||||
self.assertFalse(self.mail_mail.search(cr, uid, [('mail_message_id', '=', msg2_id)]), 'mail.mail notifications should have been auto-deleted!')
|
||||
|
||||
@@ -311,8 +311,8 @@ class test_mail_access_rights(TestMailBase):
|
||||
user_bert_id, user_raoul_id = self.user_bert_id, self.user_raoul_id
|
||||
|
||||
# Prepare groups: Pigs (employee), Jobs (public)
|
||||
pigs_msg_id = self.mail_group.message_post(cr, uid, self.group_pigs_id, body='Message', partner_ids=[(4, self.partner_admin_id)])
|
||||
jobs_msg_id = self.mail_group.message_post(cr, uid, self.group_jobs_id, body='Message', partner_ids=[(4, self.partner_admin_id)])
|
||||
pigs_msg_id = self.mail_group.message_post(cr, uid, self.group_pigs_id, body='Message', partner_ids=[self.partner_admin_id])
|
||||
jobs_msg_id = self.mail_group.message_post(cr, uid, self.group_jobs_id, body='Message', partner_ids=[self.partner_admin_id])
|
||||
|
||||
# ----------------------------------------
|
||||
# CASE1: Bert, without groups
|
||||
|
||||
@@ -204,27 +204,23 @@ class mail_compose_message(osv.TransientModel):
|
||||
'subject': wizard.subject,
|
||||
'body': wizard.body,
|
||||
'parent_id': wizard.parent_id and wizard.parent_id.id,
|
||||
'partner_ids': [(4, partner.id) for partner in wizard.partner_ids],
|
||||
'partner_ids': [partner.id for partner in wizard.partner_ids],
|
||||
'attachments': [(attach.datas_fname or attach.name, base64.b64decode(attach.datas)) for attach in wizard.attachment_ids],
|
||||
}
|
||||
# mass mailing: render and override default values
|
||||
if mass_mail_mode and wizard.model:
|
||||
email_dict = self.render_message(cr, uid, wizard, res_id, context=context)
|
||||
new_partner_ids = email_dict.pop('partner_ids', [])
|
||||
post_values['partner_ids'] += [(4, partner_id) for partner_id in new_partner_ids]
|
||||
post_values['partner_ids'] += new_partner_ids
|
||||
new_attachments = email_dict.pop('attachments', [])
|
||||
post_values['attachments'] += new_attachments
|
||||
post_values.update(email_dict)
|
||||
# automatically subscribe recipients if asked to
|
||||
if context.get('mail_post_autofollow') and wizard.model and post_values.get('partner_ids'):
|
||||
active_model_pool.message_subscribe(cr, uid, [res_id], [item[1] for item in post_values.get('partner_ids')], context=context)
|
||||
active_model_pool.message_subscribe(cr, uid, [res_id], post_values.get('partner_ids'), context=context)
|
||||
# post the message
|
||||
active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values)
|
||||
|
||||
# post process: update attachments, because id is not necessarily known when adding attachments in Chatter
|
||||
# self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], {
|
||||
# 'res_id': wizard.id, 'res_model': wizard.model or False}, context=context)
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def render_message(self, cr, uid, wizard, res_id, context=None):
|
||||
@@ -258,7 +254,7 @@ class mail_compose_message(osv.TransientModel):
|
||||
result = eval(exp, {
|
||||
'user': self.pool.get('res.users').browse(cr, uid, uid, context=context),
|
||||
'object': self.pool.get(model).browse(cr, uid, res_id, context=context),
|
||||
'context': dict(context), # copy context to prevent side-effects of eval
|
||||
'context': dict(context), # copy context to prevent side-effects of eval
|
||||
})
|
||||
return result and tools.ustr(result) or ''
|
||||
return template and EXPRESSION_PATTERN.sub(merge, template)
|
||||
|
||||
Reference in New Issue
Block a user