From 4a55165597a9cfe931ef62aa6d29404ff1d671c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 20 Dec 2013 10:27:56 +0100 Subject: [PATCH] [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 --- addons/email_template/email_template.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py index 6e19b1eb8aa..3139d5bc14b 100644 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@ -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))