From 42ab7c09ea63c65976f7f3065056a272c297f4ac Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Mon, 1 Jun 2015 11:42:52 +0200 Subject: [PATCH] New architecture for smsclient --- smsclient_ovh/__init__.py | 25 ++++++++++ smsclient_ovh/__openerp__.py | 63 +++++++++++++++++++++++ smsclient_ovh/smsclient.py | 96 ++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 smsclient_ovh/__init__.py create mode 100644 smsclient_ovh/__openerp__.py create mode 100644 smsclient_ovh/smsclient.py diff --git a/smsclient_ovh/__init__.py b/smsclient_ovh/__init__.py new file mode 100644 index 0000000..aa82470 --- /dev/null +++ b/smsclient_ovh/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# Copyright (C) 2013 Julius Network Solutions SARL +# +# This program is free software: you can redistribute it and/or modify +# 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. +# +# 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 +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import smsclient + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/smsclient_ovh/__openerp__.py b/smsclient_ovh/__openerp__.py new file mode 100644 index 0000000..7a3831e --- /dev/null +++ b/smsclient_ovh/__openerp__.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 OpenERP SA () +# Copyright (C) 2011 SYLEAM () +# Copyright (C) 2013 Julius Network Solutions SARL +# +# This program is free software: you can redistribute it and/or modify +# 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. +# +# 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 +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + "name": "SMS Client OVH", + "version": "1.0", + "depends": ["base", + "email_template", + "smsclient_core", + ], + "author": "Julius Network Solutions,SYLEAM,OpenERP SAi,Akretion", + 'images': ['images/sms.jpeg', 'images/gateway.jpeg', 'images/gateway_access.jpeg','images/client.jpeg','images/send_sms.jpeg'], + "description": """ +SMS Client module provides: +------------- +Sending SMSs very easily, individually or collectively. + +*Generalities + +OpenERP does not directly generate the SMS you will have to subscribe to an operator with a web interface (Type OVH) or via a URL generation. +If you want to use a 'SMPP Method' you must have to install the library "Soap" which can be installed with: apt-get install python-soappy. +You can find it on https://pypi.python.org/pypi/SOAPpy/ +You don't need it if you use a "HTTP Method' to send the SMS. + +*Use Multiple Gateways. + +The Gateway configuration is performed directly in the configuration menu. For each gateway, you have to fill in the information for your operator. + +To validate Gateway, code is send to a mobile phone, when received enter it to confirm SMS account. + +This Module was developped by SYLEAM and OpenERP SA in a first place. +Then, it was updated to the 7.0 version by Julius Network Solutions. + """, + "website": "http://julius.fr", + "category": "Tools", + "demo": [], + "data": [ + ], + "active": False, + "installable": True, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/smsclient_ovh/smsclient.py b/smsclient_ovh/smsclient.py new file mode 100644 index 0000000..ea64f6c --- /dev/null +++ b/smsclient_ovh/smsclient.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for OpenERP +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# 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. +# +# 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 +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from openerp import fields, api, models, _ +from openerp.exceptions import Warning +import urllib +import logging +_logger = logging.getLogger(__name__) + +try: + from SOAPpy import WSDL +except: + _logger.warning("ERROR IMPORTING SOAPpy, if not installed, please install" + "it: e.g.: apt-get install python-soappy") + + +class smsclient(models.Model): + _inherit = "sms.smsclient" + + @api.model + def get_method(self): + method = super(smsclient, self).get_method() + method.append(('ovh smpp', 'OVH SMPP'), ) + return method + + @api.onchange('method') + def onchange_method(self): + super(smsclient, self).onchange_method() + if self.method == 'ovh http': + self.url_visible = True + self.sms_account_visible = True + self.login_provider_visible = True + self.password_provider_visible = True + self.from_provider_visible = True + self.validity_visible = True + self.classes_visible = True + self.deferred_visible = True + self.nostop_visible = True + self.priority_visible = True + self.coding_visible = True + self.tag_visible = True + self.char_limit_visible = True + + @api.model + def _send_message(self, data): + super(smsclient, self)._send_message(data) + gateway = data.gateway + if gateway: + if not self._check_permissions(gateway): + raise Warning(_('You have no permission to access %s ') + % (gateway.name,)) + url = gateway.url + name = url + if gateway.method == 'http': + prms = {} + prms['smsAccount'] = gateway.sms_account + prms['login'] = gateway.login_provider + prms['password'] = gateway.password_provider + prms['from'] = gateway.from_provider + prms['to'] = data.mobile_to + prms['message'] = data.text + if gateway.nostop: + prms['noStop'] = 1 + if gateway.deferred: + prms['deferred'] = gateway.deferred + if gateway.classes: + prms['class'] = gateway.classes + if gateway.tag: + prms['tag'] = gateway.tag + if gateway.coding: + prms['smsCoding'] = gateway.coding + params = urllib.urlencode(prms) + name = url + "?" + params + queue_obj = self.env['sms.smsclient.queue'] + vals = self._prepare_smsclient_queue(data, name) + queue_obj.create(vals) + return True