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"/>
49 <separator colspan="4" string="Set case state to"/>
51 <field name="state" />
55 'to': {'string':"To", 'type':'char', 'size':64, 'required':True},
56 'cc': {'string':"CC", 'type':'char', 'size':128,},
57 'subject': {'string':'Subject', 'type':'char', 'size':128, 'required':True},
58 'text': {'string':'Message', 'type':'text_tag', 'required':True},
59 'state':{'string':'State', 'type':'selection', 'selection':[('done','Done'),('pending','Pending'),('unchanged','Unchanged')]},
60 'doc1' : {'string':"Attachment1", 'type':'binary'},
61 'doc2' : {'string':"Attachment2", 'type':'binary'},
62 'doc3' : {'string':"Attachment3", 'type':'binary'},
63 'state' : {'string':"Set State to", 'type':'selection', 'required' : True, 'default' :'done',\
64 'selection': [('unchanged','Unchanged'),('done','Done'),('pending','Pending')]},
67 # this sends an email to ALL the addresses of the selected partners.
68 def _mass_mail_send(self, cr, uid, data, context):
69 attach = filter(lambda x: x, [data['form']['doc1'], data['form']['doc2'], data['form']['doc3']])
70 attach = map(lambda x: x and ('Attachment'+str(attach.index(x)+1), base64.decodestring(x)), attach)
72 pool = pooler.get_pool(cr.dbname)
73 case_pool=pool.get('crm.case')
75 case = case_pool.browse(cr,uid,data['ids'])[0]
76 case_pool.write(cr, uid, [case.id], {
80 emails = [data['form']['to']] + (data['form']['cc'] or '').split(',')
81 emails = filter(None, emails)
82 body = data['form']['text']
83 if not case.user_id.address_id.email:
84 raise wizard.except_wizard(_('Warning!'),_("Please specify user's email address !"))
85 if case.user_id.signature:
86 body += '\n\n%s' % (case.user_id.signature)
87 case_pool._history(cr, uid, [case], _('Send'), history=True, email=False, details=body)
88 flag = tools.email_send(
89 case.user_id.address_id.email,
91 data['form']['subject'],
93 case_pool.format_body(body),
95 reply_to=case.section_id.reply_to,
99 if data['form']['state'] == 'unchanged':
101 elif data['form']['state'] == 'done':
102 case_pool.case_close(cr, uid, data['ids'])
103 elif data['form']['state'] == 'pending':
104 case_pool.case_pending(cr, uid, data['ids'])
107 raise wizard.except_wizard(_('Warning!'),_("Email not sent !"))
110 def _get_info(self, cr, uid, data, context):
113 pool = pooler.get_pool(cr.dbname)
114 case = pool.get('crm.case').browse(cr,uid,data['ids'])[0]
115 #if not case.email_from:
116 # raise wizard.except_wizard(_('Error'),_('You must put a Partner eMail to use this action!'))
118 raise wizard.except_wizard(_('Error'),_('You must define a responsible user for this case in order to use this action!'))
119 return {'to': case.email_from,'subject': case.name,'cc': case.email_cc or ''}
121 class wizard_send_mail(wizard.interface):
124 'actions': [_get_info],
125 'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel','gtk-cancel'), ('send','Send Email','gtk-go-forward')]}
128 'actions': [_mass_mail_send],
129 'result': {'type': 'state', 'state':'end'}
132 wizard_send_mail('crm.new.send.mail')
133 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: