~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to auction/wizard/wizard_lots_sms.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-12 06:43:12 UTC
  • Revision ID: fp@tinyerp.com-20081112064312-fp85io97i1e95tuz
moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2004 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
 
import urllib
33
 
 
34
 
sms_send_form = '''<?xml version="1.0"?>
35
 
<form title="%s">
36
 
        <separator string="%s" colspan="4"/>
37
 
        <field name="app_id"/>
38
 
        <newline/>
39
 
        <field name="user"/>
40
 
        <field name="password"/>
41
 
        <newline/>
42
 
        <field name="text" colspan="3"/>
43
 
</form>''' % ('SMS - Gateway: clickatell', 'Bulk SMS send')
44
 
 
45
 
sms_send_fields = {
46
 
        'app_id': {'string':'API ID', 'type':'char', 'required':True},
47
 
        'user': {'string':'Login', 'type':'char', 'required':True},
48
 
        'password': {'string':'Password', 'type':'char', 'required':True},
49
 
        'text': {'string':'SMS Message', 'type':'text', 'required':True, 'value':'Les lots [lots] vous ont etes adjuges. -- Rops'}
50
 
}
51
 
##############################################################################
52
 
#
53
 
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
54
 
#                    Fabien Pinckaers <fp@tiny.Be>
55
 
#
56
 
# WARNING: This program as such is intended to be used by professional
57
 
# programmers who take the whole responsability of assessing all potential
58
 
# consequences resulting from its eventual inadequacies and bugs
59
 
# End users who are looking for a ready-to-use solution with commercial
60
 
# garantees and support are strongly adviced to contract a Free Software
61
 
# Service Company
62
 
#
63
 
# This program is Free Software; you can redistribute it and/or
64
 
# modify it under the terms of the GNU General Public License
65
 
# as published by the Free Software Foundation; either version 2
66
 
# of the License, or (at your option) any later version.
67
 
#
68
 
# This program is distributed in the hope that it will be useful,
69
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
70
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
71
 
# GNU General Public License for more details.
72
 
#
73
 
# You should have received a copy of the GNU General Public License
74
 
# along with this program; if not, write to the Free Software
75
 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
76
 
#
77
 
##############################################################################
78
 
 
79
 
import wizard
80
 
import netsvc
81
 
import pooler
82
 
 
83
 
sms_send_form = '''<?xml version="1.0"?>
84
 
<form string="%s">
85
 
        <separator string="%s" colspan="4"/>
86
 
        <field name="app_id"/>
87
 
        <newline/>
88
 
        <field name="user"/>
89
 
        <field name="password"/>
90
 
        <newline/>
91
 
        <field name="text" colspan="3"/>
92
 
</form>''' % ('SMS - Gateway: clickatell','Bulk SMS send')
93
 
 
94
 
sms_send_fields = {
95
 
        'app_id': {'string':'API ID', 'type':'char', 'required':True},
96
 
        'user': {'string':'Login', 'type':'char', 'required':True},
97
 
        'password': {'string':'Password', 'type':'char', 'required':True},
98
 
        'text': {'string':'SMS Message', 'type':'text', 'required':True}
99
 
}
100
 
 
101
 
def _sms_send(self, cr, uid, data, context):
102
 
        service = netsvc.LocalService("object_proxy")
103
 
        lots = service.execute(cr.dbname,uid, 'auction.lots', 'read', data['ids'], ['obj_num','obj_price','ach_uid'])
104
 
        res = service.execute(cr.dbname,uid, 'res.partner', 'read', [l['ach_uid'] for l in lots if l['ach_uid']], ['gsm'])
105
 
        #res = service.execute(cr.dbname, uid, 'res.partner', 'read', data['ids'], ['gsm'])
106
 
#       service = netsvc.LocalService("object_proxy")
107
 
#       pool=pooler.get_pool(cr.dbname)
108
 
#       lots=pool.get('auction.lots').browse(cr,uid,data['id'],context)
109
 
#       r=lots.ach_uid.id
110
 
        nbr = 0
111
 
        for r in res:
112
 
                to = r['mobile']
113
 
                if to:
114
 
                        tools.smssend(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
115
 
                        nbr += 1
116
 
        return {'sms_sent': nbr}
117
 
 
118
 
        if to:
119
 
                tools.smssend(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
120
 
                nbr += 1
121
 
        return {'sms_sent': nbr}
122
 
#
123
 
#def _sms_send(self, uid, datas):
124
 
#       service = netsvc.LocalService("object_proxy")
125
 
#       pool=pooler.ger_pool(cr.dbname)
126
 
#       lots=pool.get('auction.lots').browse(cr,uid,datas['ids'],context)
127
 
#       #lots = service.execute(uid, 'auction.lots', 'read', datas['ids'], ['obj_num','obj_price','ach_uid'])
128
 
#       #part = service.execute(uid, 'res.partner', 'read', [l['ach_uid'] for l in lots if l['ach_uid']], ['gsm'])
129
 
#       
130
 
#       part =ach_uid.id
131
 
#       part = map(lambda x: (x.id,x.mobile), part)
132
 
#       for l in lots:
133
 
#               part.append(str(l.obj_num)+'-%dEUR' % int(l.obj_price))
134
 
#
135
 
#       for p in part.values():
136
 
#               to = p.mobile
137
 
#               if to:
138
 
#                       params = urllib.urlencode({'user': datas['form']['user'], 'password': datas['form']['password'], 'api_id': datas['form']['app_id'], 'text':unicode(datas['form']['text'].replace('[lots]',', '.join(p['lots'])), 'utf-8').encode('latin1'), 'to':to})
139
 
#                       f = urllib.urlopen("http://196.7.150.220/http/sendmsg", params)
140
 
#                       nbr+=1
141
 
#       return {'sms_sent':nbr}
142
 
 
143
 
class lots_sms(wizard.interface):
144
 
        states = {
145
 
                'init': {
146
 
                        'actions': [],
147
 
                        'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('send','Send SMS'), ('end','Cancel')]}
148
 
                },
149
 
                'send': {
150
 
                        'actions': [_sms_send],
151
 
                        'result': {'type': 'state', 'state':'end'}
152
 
                }
153
 
        }
154
 
lots_sms('auction.lots.sms_send');
155