Launchpad automatic translations update.
[odoo/odoo.git] / bin / addons / base / res / partner / wizard / wizard_sms.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22 import wizard
23 import netsvc
24 import tools
25
26 sms_send_form = '''<?xml version="1.0"?>
27 <form string="%s">
28     <separator string="%s" colspan="4"/>
29     <field name="app_id"/>
30     <newline/>
31     <field name="user"/>
32     <field name="password"/>
33     <newline/>
34     <field name="text" colspan="4"/>
35 </form>''' % ('SMS - Gateway: clickatell','Bulk SMS send')
36
37 sms_send_fields = {
38     'app_id': {'string':'API ID', 'type':'char', 'required':True},
39     'user': {'string':'Login', 'type':'char', 'required':True},
40     'password': {'string':'Password', 'type':'char', 'required':True},
41     'text': {'string':'SMS Message', 'type':'text', 'required':True}
42 }
43
44 def _sms_send(self, cr, uid, data, context):
45     service = netsvc.LocalService("object_proxy")
46
47     res_ids = service.execute(cr.dbname, uid, 'res.partner.address', 'search', [('partner_id','in',data['ids']),('type','=','default')])
48     res = service.execute(cr.dbname, uid, 'res.partner.address', 'read', res_ids, ['mobile'])
49
50     nbr = 0
51     for r in res:
52         to = r['mobile']
53         if to:
54             tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
55             nbr += 1
56     return {'sms_sent': nbr}
57
58 class part_sms(wizard.interface):
59     states = {
60         'init': {
61             'actions': [],
62             'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('end','Cancel'), ('send','Send SMS')]}
63         },
64         'send': {
65             'actions': [_sms_send],
66             'result': {'type': 'state', 'state':'end'}
67         }
68     }
69 part_sms('res.partner.sms_send')
70
71
72
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
74