[FIX] email_template: when sending email, process partner_to value also to convet it into a recipient_ids.

Hint: backport me into saas-2 or even 7.0

bzr revid: tde@openerp.com-20131220092756-o2qx54cjfq0qbsc9
This commit is contained in:
Thibault Delavallée
2013-12-20 10:27:56 +01:00
parent 8fa229061a
commit 4a55165597
+15 -6
View File
@@ -411,7 +411,16 @@ class email_template(osv.osv):
# create a mail_mail based on values, without attachments
values = self.generate_email(cr, uid, template_id, res_id, context=context)
assert values.get('email_from'), 'email_from is missing or empty after template rendering, send_mail() cannot proceed'
del values['partner_to'] # TODO Properly use them.
# process partner_to field that is a comma separated list of partner_ids -> recipient_ids
# TDENOTE: should probably be done in saas / 7.0, FIXME
values['recipient_ids'] = []
partner_to = values.pop('partner_to', '')
if partner_to:
for partner_id in partner_to.split(','):
if partner_id: # placeholders could generate '', 3, 2 due to some empty field values
values['recipient_ids'].append((4, int(partner_id)))
attachment_ids = values.pop('attachment_ids', [])
attachments = values.pop('attachments', [])
msg_id = mail_mail.create(cr, uid, values, context=context)
@@ -420,11 +429,11 @@ class email_template(osv.osv):
# manage attachments
for attachment in attachments:
attachment_data = {
'name': attachment[0],
'datas_fname': attachment[0],
'datas': attachment[1],
'res_model': 'mail.message',
'res_id': mail.mail_message_id.id,
'name': attachment[0],
'datas_fname': attachment[0],
'datas': attachment[1],
'res_model': 'mail.message',
'res_id': mail.mail_message_id.id,
}
context.pop('default_type', None)
attachment_ids.append(ir_attachment.create(cr, uid, attachment_data, context=context))