~openerp-dev/openobject-server/trunk-bug-712254-ysa

« back to all changes in this revision

Viewing changes to bin/addons/base/res/partner/wizard/wizard_sms.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
import wizard
 
30
import netsvc
 
31
 
 
32
sms_send_form = '''<?xml version="1.0"?>
 
33
<form string="%s">
 
34
        <separator string="%s" colspan="4"/>
 
35
        <field name="app_id"/>
 
36
        <newline/>
 
37
        <field name="user"/>
 
38
        <field name="password"/>
 
39
        <newline/>
 
40
        <field name="text" colspan="3"/>
 
41
</form>''' % ('SMS - Gateway: clickatell','Bulk SMS send')
 
42
 
 
43
sms_send_fields = {
 
44
        'app_id': {'string':'API ID', 'type':'char', 'required':True},
 
45
        'user': {'string':'Login', 'type':'char', 'required':True},
 
46
        'password': {'string':'Password', 'type':'char', 'required':True},
 
47
        'text': {'string':'SMS Message', 'type':'text', 'required':True}
 
48
}
 
49
 
 
50
def _sms_send(self, cr, uid, data, context):
 
51
        service = netsvc.LocalService("object_proxy")
 
52
        res = service.execute(cr.dbname, uid, 'res.partner', 'read', data['ids'], ['gsm'])
 
53
 
 
54
        nbr = 0
 
55
        for r in res:
 
56
                to = r['gsm']
 
57
                if to:
 
58
                        tools.smssend(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
 
59
                        nbr += 1
 
60
        return {'sms_sent': nbr}
 
61
 
 
62
class part_sms(wizard.interface):
 
63
        states = {
 
64
                'init': {
 
65
                        'actions': [],
 
66
                        'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('end','Cancel'), ('send','Send SMS')]}
 
67
                },
 
68
                'send': {
 
69
                        'actions': [_sms_send],
 
70
                        'result': {'type': 'state', 'state':'end'}
 
71
                }
 
72
        }
 
73
part_sms('res.partner.sms_send')
 
74
 
 
75