From 80f77a429d465cc782006f752cfdb07e690a7c25 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Mon, 24 Nov 2008 12:15:30 +0100 Subject: [PATCH] [REF] Clean the code for email_send bzr revid: stephane@tinyerp.com-20081124111530-ujuxdgwc25nft7mx --- addons/crm/crm.py | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 192ee2e057e..d284da54904 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -594,30 +594,25 @@ class crm_case(osv.osv): if case.user_id.signature: body += '\n\n%s' % (case.user_id.signature) dest = [dest] - if not attach: - tools.email_send( - src, - dest, - 'Reminder: '+'['+str(case.id)+']'+' '+case.name, - body, - reply_to=case.section_id.reply_to, tinycrm=str(case.id) - ) - else: - attach_ids = self.pool.get('ir.attachment').search(cr, uid, - [('res_model', '=', 'crm.case'), - ('res_id', '=', case.id)]) - res = self.pool.get('ir.attachment').read(cr, uid, - attach_ids, ['datas_fname','datas']) - res = map(lambda x: (x['datas_fname'], - base64.decodestring(x['datas'])), res) - tools.email_send_attach( - src, - dest, - 'Reminder: '+'['+str(case.id)+']'+' '+case.name, - body, - reply_to=case.section_id.reply_to, - attach=res, tinycrm=str(case.id) - ) + + attach_to_send = None + + if attach: + attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', 'crm.case'), ('res_id', '=', case.id)]) + attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname','datas']) + attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send) + + # Send an email + tools.email_send( + src, + dest, + "Reminder: [%s] %s" % (str(case.id), case.name, ), + body, + reply_to=case.section_id.reply_to, + tinycrm=str(case.id), + attach=attach_to_send + ) + return True def add_reply(self, cursor, user, ids, context=None): @@ -653,9 +648,14 @@ class crm_case(osv.osv): body = case.description if case.user_id.signature: body += '\n\n%s' % (case.user_id.signature) - tools.email_send(case.user_id.address_id.email, emails, - '['+str(case.id)+'] '+case.name, body, - reply_to=case.section_id.reply_to, tinycrm=str(case.id)) + tools.email_send( + case.user_id.address_id.email, + emails, + '['+str(case.id)+'] '+case.name, + body, + reply_to=case.section_id.reply_to, + tinycrm=str(case.id) + ) return True def onchange_partner_id(self, cr, uid, ids, part, email=False):