2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-10-14 12:32:15 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import wizard
|
|
|
|
import netsvc
|
2008-03-17 13:14:31 +00:00
|
|
|
import tools
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
sms_send_form = '''<?xml version="1.0"?>
|
|
|
|
<form string="%s">
|
2008-07-22 14:24:36 +00:00
|
|
|
<separator string="%s" colspan="4"/>
|
|
|
|
<field name="app_id"/>
|
|
|
|
<newline/>
|
|
|
|
<field name="user"/>
|
|
|
|
<field name="password"/>
|
|
|
|
<newline/>
|
|
|
|
<field name="text" colspan="4"/>
|
2006-12-07 13:41:40 +00:00
|
|
|
</form>''' % ('SMS - Gateway: clickatell','Bulk SMS send')
|
|
|
|
|
|
|
|
sms_send_fields = {
|
2008-07-22 14:24:36 +00:00
|
|
|
'app_id': {'string':'API ID', 'type':'char', 'required':True},
|
|
|
|
'user': {'string':'Login', 'type':'char', 'required':True},
|
|
|
|
'password': {'string':'Password', 'type':'char', 'required':True},
|
|
|
|
'text': {'string':'SMS Message', 'type':'text', 'required':True}
|
2006-12-07 13:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _sms_send(self, cr, uid, data, context):
|
2008-07-22 14:24:36 +00:00
|
|
|
service = netsvc.LocalService("object_proxy")
|
2008-03-17 13:14:31 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
res_ids = service.execute(cr.dbname, uid, 'res.partner.address', 'search', [('partner_id','in',data['ids']),('type','=','default')])
|
|
|
|
res = service.execute(cr.dbname, uid, 'res.partner.address', 'read', res_ids, ['mobile'])
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
nbr = 0
|
|
|
|
for r in res:
|
|
|
|
to = r['mobile']
|
|
|
|
if to:
|
|
|
|
tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
|
|
|
|
nbr += 1
|
|
|
|
return {'sms_sent': nbr}
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class part_sms(wizard.interface):
|
2008-07-22 14:24:36 +00:00
|
|
|
states = {
|
|
|
|
'init': {
|
|
|
|
'actions': [],
|
|
|
|
'result': {'type': 'form', 'arch':sms_send_form, 'fields': sms_send_fields, 'state':[('end','Cancel'), ('send','Send SMS')]}
|
|
|
|
},
|
|
|
|
'send': {
|
|
|
|
'actions': [_sms_send],
|
|
|
|
'result': {'type': 'state', 'state':'end'}
|
|
|
|
}
|
|
|
|
}
|
2006-12-07 13:41:40 +00:00
|
|
|
part_sms('res.partner.sms_send')
|
|
|
|
|
|
|
|
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|