1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
5
# Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
6
# Jordi Esteve <jesteve@zikzakmedia.com>
8
# WARNING: This program as such is intended to be used by professional
9
# programmers who take the whole responsability of assessing all potential
10
# consequences resulting from its eventual inadequacies and bugs
11
# End users who are looking for a ready-to-use solution with commercial
12
# garantees and support are strongly adviced to contract a Free Software
15
# This program is Free Software; you can redistribute it and/or
16
# modify it under the terms of the GNU General Public License
17
# as published by the Free Software Foundation; either version 2
18
# of the License, or (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
##############################################################################
35
sms_send_form = '''<?xml version="1.0"?>
37
<separator string="%s" colspan="4"/>
38
<field name="app_id"/>
41
<field name="password"/>
43
<field name="email_http"/>
45
<separator colspan="4"/>
46
<label string="Message:"/>
47
<field name="default"/>
48
<field name="text" nolabel="1" colspan="4"/>
50
<separator string="The following tags can be included in the message. They will be replaced to the corresponding values of each partner contact:" colspan="4"/>
51
<label string="[[partner_id]] -> Partner name" colspan="2"/>
52
<label string="[[name]] -> Contact name" colspan="2"/>
53
<label string="[[function]] -> Function" colspan="2"/>
54
<label string="[[title]] -> Title" colspan="2"/>
55
<label string="[[street]] -> Street" colspan="2"/>
56
<label string="[[street2]] -> Street 2" colspan="2"/>
57
<label string="[[zip]] -> Zip code" colspan="2"/>
58
<label string="[[city]] -> City" colspan="2"/>
59
<label string="[[state_id]] -> State" colspan="2"/>
60
<label string="[[country_id]] -> Country" colspan="2"/>
61
<label string="[[email]] -> Email" colspan="2"/>
62
<label string="[[phone]] -> Phone" colspan="2"/>
63
<label string="[[fax]] -> Fax" colspan="2"/>
64
<label string="[[mobile]] -> Mobile" colspan="2"/>
65
<label string="[[birthdate]] -> Birthday" colspan="2"/>
66
</form>''' % ('SMS - Gateway: clickatell','Bulk SMS send')
69
'app_id': {'string':'API ID', 'type':'char', 'required':True},
70
'user': {'string':'Login', 'type':'char', 'required':True},
71
'password': {'string':'Password', 'type':'char', 'required':True},
72
'email_http': {'string':'Email connection', 'type':'boolean', 'help':'HTTP or Email connection to clickatell gateway'},
73
'email': {'string':"Sender's email", 'type':'char', 'help':'Only required for Email connection to clickatell gateway', 'size':128},
74
'default': {'string':'Only send to default addresses', 'type':'boolean'},
75
'text': {'string':'SMS Message', 'type':'text', 'required':True}
78
sms_done_form = '''<?xml version="1.0"?>
80
<field name="sms_sent"/>
84
'sms_sent': {'string':'Quantity of SMS sent', 'type':'integer', 'readonly': True},
88
def _sms_send(cr, uid, data, context, adr):
90
# change the [[field]] tags with the partner address values
91
pattern = re.compile('\[\[\S+\]\]')
92
fields = pattern.findall(data['form']['text'])
95
text = getattr(adr, field[2:-2])
96
if text and field[-5:-2]=='_id': # State or country
98
texts.append(text or '')
99
sms = pattern.sub('%s', data['form']['text'])
100
sms = sms % tuple(texts)
104
to = to.replace(' ','')
105
if adr.country_id and adr.country_id.code in ('ES', 'CT') and to[:1] == '6': # Spain mobiles begin with 6
107
sms = ' '.join( sms.split('\n') ) # Conversion of '\n' to ' ' is necessary
108
sms_sent = unicode(sms, 'utf-8').encode('latin1')
109
if data['form']['email_http']:
110
# Connection by Email
111
text = 'user:' + data['form']['user'] + '\npassword:' + data['form']['password'] + '\napi_id:' + data['form']['app_id'] + '\nto:' + to + '\ntext:' + sms_sent
113
tools.email_send(data['form']['email'], ['sms@messaging.clickatell.com'], '', text)
116
tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], sms_sent, to)
118
# Add a partner event
119
c_id = pooler.get_pool(cr.dbname).get('res.partner.canal').search(cr ,uid, [('name','ilike','SMS'),('active','=',True)])
120
c_id = c_id and c_id[0] or False
121
pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
122
{'name': 'SMS sent to ' + adr.mobile,
123
'partner_id': adr.partner_id.id,
129
def _sms_send_partner(self, cr, uid, data, context):
131
criteria = [('partner_id','in',data['ids'])]
132
if data['form']['default']: # Only default addresses
133
criteria.append(('type','=','default'))
134
adr_ids = pooler.get_pool(cr.dbname).get('res.partner.address').search(cr ,uid, criteria)
135
addresses = pooler.get_pool(cr.dbname).get('res.partner.address').browse(cr, uid, adr_ids, context)
136
for adr in addresses:
138
_sms_send(cr, uid, data, context, adr)
140
return {'sms_sent': nbr}
142
class part_sms(wizard.interface):
146
'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('end','Cancel'), ('send','Send SMS')]}
149
'actions': [_sms_send_partner],
150
'result': {'type': 'form', 'arch': sms_done_form, 'fields': sms_done_fields, 'state': [('end', 'End')] }
153
part_sms('res.partner.sms_send_2')
156
def _sms_send_partner_address(self, cr, uid, data, context):
158
criteria = [('id','in',data['ids'])]
159
if data['form']['default']: # Only default addresses
160
criteria.append(('type','=','default'))
161
adr_ids = pooler.get_pool(cr.dbname).get('res.partner.address').search(cr ,uid, criteria)
162
addresses = pooler.get_pool(cr.dbname).get('res.partner.address').browse(cr, uid, adr_ids, context)
163
for adr in addresses:
165
_sms_send(cr, uid, data, context, adr)
167
return {'sms_sent': nbr}
169
class part_sms_partner_address(wizard.interface):
173
'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('end','Cancel'), ('send','Send SMS')]}
176
'actions': [_sms_send_partner_address],
177
'result': {'type': 'form', 'arch': sms_done_form, 'fields': sms_done_fields, 'state': [('end', 'End')] }
180
part_sms_partner_address('res.partner.address.sms_send')
b'\\ No newline at end of file'