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 'state':{'string':'State', 'type':'selection', 'selection':[('done','Done'),('pending','Pending'),('unchanged','Unchanged')]}
57 'doc1' : {'string':"Attachment1", 'type':'binary'},
58 'doc2' : {'string':"Attachment2", 'type':'binary'},
59 'doc3' : {'string':"Attachment3", 'type':'binary'},
62 # this sends an email to ALL the addresses of the selected partners.
63 def _mass_mail_send(self, cr, uid, data, context):
64 attach = filter(lambda x: x, [data['form']['doc1'], data['form']['doc2'], data['form']['doc3']])
65 attach = map(lambda x: x and ('Attachment'+str(attach.index(x)+1), base64.decodestring(x)), attach)
67 pool = pooler.get_pool(cr.dbname)
68 case_pool=pool.get('crm.case')
70 case = case_pool.browse(cr,uid,data['ids'])[0]
71 case_pool._history(cr, uid, [case], _('Send'), history=True, email=False)
72 case_pool.write(cr, uid, [case.id], {
76 emails = [data['form']['to']] + (data['form']['cc'] or '').split(',')
77 emails = filter(None, emails)
78 body = data['form']['text']
79 if case.user_id.signature:
80 body += '\n\n%s' % (case.user_id.signature)
81 flag = tools.email_send(
82 case.user_id.address_id.email,
84 data['form']['subject'],
87 case_pool.format_body(body),
88 reply_to=case.section_id.reply_to,
92 raise wizard.except_wizard(_('Message!'),("Email Successfully Sent..!!"))
94 raise wizard.except_wizard(_('Warning!'),("Email is not sent Successfully"))
97 def _get_info(self, cr, uid, data, context):
100 pool = pooler.get_pool(cr.dbname)
101 case = pool.get('crm.case').browse(cr,uid,data['ids'])[0]
102 if not case.email_from:
103 raise wizard.except_wizard(_('Error'),_('You must put a Partner eMail to use this action!'))
105 raise wizard.except_wizard(_('Error'),_('You must define a responsible user for this case in order to use this action!'))
106 return {'to': case.email_from,'subject': '['+str(case.id)+'] '+case.name,'cc': case.email_cc or ''}
108 class wizard_send_mail(wizard.interface):
111 'actions': [_get_info],
112 'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel','gtk-cancel'), ('send','Send Email','gtk-go-forward')]}
115 'actions': [_mass_mail_send],
116 'result': {'type': 'state', 'state':'end'}
119 wizard_send_mail('crm.new.send.mail')
120 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: