1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from mx.DateTime import now
31 from tools.translate import _
34 email_send_form = '''<?xml version="1.0"?>
35 <form string="Mass Mailing">
40 <field name="subject"/>
52 'to': {'string':"To", 'type':'char', 'size':64, 'required':True},
53 'cc': {'string':"CC", 'type':'char', 'size':128,},
54 'subject': {'string':'Subject', 'type':'char', 'size':128, 'required':True},
55 'text': {'string':'Message', 'type':'text_tag', 'required':True},
56 'doc1' : {'string':"Attachment1", 'type':'binary'},
57 'doc2' : {'string':"Attachment2", 'type':'binary'},
58 'doc3' : {'string':"Attachment3", 'type':'binary'},
61 # this sends an email to ALL the addresses of the selected partners.
62 def _mass_mail_send(self, cr, uid, data, context):
63 attach = filter(lambda x: x, [data['form']['doc1'], data['form']['doc2'], data['form']['doc3']])
64 attach = map(lambda x: x and ('Attachment'+str(attach.index(x)+1), base64.decodestring(x)), attach)
66 pool = pooler.get_pool(cr.dbname)
67 case_pool=pool.get('crm.case')
69 case = case_pool.browse(cr,uid,data['ids'])[0]
70 case_pool._history(cr, uid, [case], _('Send'), history=True, email=False)
71 case_pool.write(cr, uid, [case.id], {
75 emails = [data['form']['to']] + (data['form']['cc'] or '').split(',')
76 emails = filter(None, emails)
77 body = data['form']['text']
78 if case.user_id.signature:
79 body += '\n\n%s' % (case.user_id.signature)
80 flag = tools.email_send(
81 case.user_id.address_id.email,
83 data['form']['subject'],
86 case_pool.format_body(body),
87 reply_to=case.section_id.reply_to,
91 raise wizard.except_wizard(_('Message!'),("Email Successfully Sent..!!"))
93 raise wizard.except_wizard(_('Warning!'),("Email is not sent Successfully"))
96 def _get_info(self, cr, uid, data, context):
99 pool = pooler.get_pool(cr.dbname)
100 case = pool.get('crm.case').browse(cr,uid,data['ids'])[0]
101 if not case.email_from:
102 raise wizard.except_wizard(_('Error'),_('You must put a Partner eMail to use this action!'))
104 raise wizard.except_wizard(_('Error'),_('You must define a responsible user for this case in order to use this action!'))
105 return {'to': case.email_from,'subject': '['+str(case.id)+'] '+case.name,'cc': case.email_cc or ''}
107 class wizard_send_mail(wizard.interface):
110 'actions': [_get_info],
111 'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel','gtk-cancel'), ('send','Send Email','gtk-go-forward')]}
114 'actions': [_mass_mail_send],
115 'result': {'type': 'state', 'state':'end'}
118 wizard_send_mail('crm.new.send.mail')
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: