From 5ebf390f965f369bc4c29c7e5cf4232480d34bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 8 Mar 2013 10:11:56 +0100 Subject: [PATCH] [FIX] email_template: void value in partner_ids when generating tmeplate does not erase wizard value anymore. bzr revid: tde@openerp.com-20130308091156-ytw5k4y5w321705f --- .../wizard/mail_compose_message.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py index b39ed4e5639..e9f539a22b2 100644 --- a/addons/email_template/wizard/mail_compose_message.py +++ b/addons/email_template/wizard/mail_compose_message.py @@ -70,6 +70,7 @@ class mail_compose_message(osv.TransientModel): elif template_id: # FIXME odo: change the mail generation to avoid attachment duplication values = self.generate_email_for_composer(cr, uid, template_id, res_id, context=context) + print values.get('partner_ids') # transform attachments into attachment_ids values['attachment_ids'] = [] ir_attach_obj = self.pool.get('ir.attachment') @@ -80,7 +81,7 @@ class mail_compose_message(osv.TransientModel): 'datas_fname': attach_fname, 'res_model': model, 'res_id': res_id, - 'type': 'binary', # override default_type from context, possibly meant for another model! + 'type': 'binary', # override default_type from context, possibly meant for another model! } values['attachment_ids'].append(ir_attach_obj.create(cr, uid, data_attach, context=context)) else: @@ -125,19 +126,22 @@ class mail_compose_message(osv.TransientModel): fields = ['body_html', 'subject', 'email_to', 'email_recipients', 'email_cc', 'attachments'] values = dict((field, template_values[field]) for field in fields if template_values.get(field)) values['body'] = values.pop('body_html', '') - # transform email_to, email_cc into partner_ids - values['partner_ids'] = [] + # transform email_to, email_cc into partner_ids + partner_ids = set() mails = tools.email_split(values.pop('email_to', '') + ' ' + values.pop('email_cc', '')) for mail in mails: partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context) - values['partner_ids'].append(partner_id) + partner_ids.add(partner_id) email_recipients = values.pop('email_recipients', '') if email_recipients: for partner_id in email_recipients.split(','): - values['partner_ids'].append(int(partner_id)) - - values['partner_ids'] = list(set(values['partner_ids'])) + if partner_id: # placeholders could generate '', 3, 2 due to some empty field values + partner_ids.add(int(partner_id)) + # legacy template behavior: void values do not erase existing values and the + # related key is removed from the values dict + if partner_ids: + values['partner_ids'] = [(6, 0, list(partner_ids))] return values