MonsieurB
8 years ago
14 changed files with 224 additions and 291 deletions
-
2smsclient_core/models/serveraction.py
-
84smsclient_core/models/sms_gateway.py
-
2smsclient_core/models/smstemplate.py
-
37smsclient_core/views/sms_gateway_view.xml
-
25smsclient_core/wizard/mass_sms.py
-
13smsclient_ovh/README.rst
-
27smsclient_ovh/__init__.py
-
32smsclient_ovh/__manifest__.py
-
49smsclient_ovh/__openerp__.py
-
9smsclient_ovh/data/keychain.xml
-
7smsclient_ovh/models/__init__.py
-
45smsclient_ovh/models/keychain.py
-
86smsclient_ovh/models/sms_gateway.py
-
97smsclient_ovh/sms_gateway.py
@ -1,23 +1,6 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). |
|||
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr> |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
# coding: utf-8 |
|||
# Copyright (C) 2015 Sébastien BEAU <sebastien.beau@akretion.com> |
|||
# Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import sms_gateway |
|||
from . import models |
@ -0,0 +1,32 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr> |
|||
# Copyright (C) 2015 Sébastien BEAU <sebastien.beau@akretion.com> |
|||
|
|||
{ |
|||
'name': 'SMS Client OVH', |
|||
'version': '10.0.1.0.0', |
|||
'depends': ['base', |
|||
'mail', |
|||
'smsclient_core', |
|||
'base_suspend_security', |
|||
'keychain', |
|||
], |
|||
'author': 'Julius Network Solutions,SYLEAM,OpenERP SA,' |
|||
'Odoo Community Association (OCA),Akretion', |
|||
'images': [ |
|||
'images/sms.jpeg', |
|||
'images/gateway.jpeg', |
|||
'images/gateway_access.jpeg', |
|||
'images/client.jpeg', |
|||
'images/send_sms.jpeg' |
|||
], |
|||
'website': 'http://julius.fr', |
|||
'category': 'Tools', |
|||
'demo': [], |
|||
'data': [ |
|||
], |
|||
'active': False, |
|||
'installable': True, |
|||
} |
|||
|
|||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
@ -1,49 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2004-2009 OpenERP SA (<http://openerp.com>) |
|||
# Copyright (C) 2011 SYLEAM (<http://syleam.fr/>) |
|||
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr> |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
{ |
|||
"name": "SMS Client OVH", |
|||
"version": "1.0", |
|||
"depends": ["base", |
|||
"email_template", |
|||
"smsclient_core", |
|||
], |
|||
"author": "Julius Network Solutions,SYLEAM,OpenERP SA," |
|||
"Odoo Community Association (OCA),Akretion", |
|||
'images': [ |
|||
'images/sms.jpeg', |
|||
'images/gateway.jpeg', |
|||
'images/gateway_access.jpeg', |
|||
'images/client.jpeg', |
|||
'images/send_sms.jpeg' |
|||
], |
|||
"website": "http://julius.fr", |
|||
"category": "Tools", |
|||
"demo": [], |
|||
"data": [ |
|||
], |
|||
"active": False, |
|||
"installable": True, |
|||
} |
|||
|
|||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
@ -0,0 +1,9 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo noupdate="1"> |
|||
<record id="keychain_ovh" model="keychain.account"> |
|||
<field name="name">Ovh sms default</field> |
|||
<field name="namespace">ovh_provider</field> |
|||
<field name="technical_name">ovh_default_account</field> |
|||
</record> |
|||
|
|||
</odoo> |
@ -0,0 +1,7 @@ |
|||
# coding: utf-8 |
|||
# Copyright (C) 2015 Sébastien BEAU <sebastien.beau@akretion.com> |
|||
# Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import sms_gateway |
|||
from . import keychain |
@ -0,0 +1,45 @@ |
|||
# coding: utf-8 |
|||
# Copyright (C) 2015 Sébastien BEAU <sebastien.beau@akretion.com> |
|||
# Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from odoo import models, fields |
|||
from functools import wraps |
|||
|
|||
|
|||
def implemented_by_provider(func): |
|||
"""Decorator: call _provider_prefixed method instead. |
|||
Usage: |
|||
@implemented_by_provider |
|||
def _do_something() |
|||
def _laposte_do_something() |
|||
def _gls_do_something() |
|||
At runtime, sms-client._do_something() will try to call |
|||
the provider spectific method or fallback to generic _do_something |
|||
""" |
|||
@wraps(func) |
|||
def wrapper(cls, *args, **kwargs): |
|||
fun_name = func.__name__ |
|||
fun = '_%s%s' % (cls.provider_type, fun_name) |
|||
if not hasattr(cls, fun): |
|||
fun = '_provider%s' % (fun_name) |
|||
# return func(cls, *args, **kwargs) |
|||
return getattr(cls, fun)(*args, **kwargs) |
|||
return wrapper |
|||
|
|||
|
|||
OVH_KEYCHAIN_NAMESPACE = 'ovh_provider' |
|||
|
|||
|
|||
class AccountProduct(models.Model): |
|||
_inherit = 'keychain.account' |
|||
|
|||
namespace = fields.Selection( |
|||
selection_add=[(OVH_KEYCHAIN_NAMESPACE, 'Ovh_sms')]) |
|||
|
|||
def _ovh_provider_init_data(self): |
|||
return {'sms_account': ""} |
|||
|
|||
def _ovh_provider_validate_data(self, data): |
|||
|
|||
return True |
@ -0,0 +1,86 @@ |
|||
# coding: utf-8 |
|||
# Copyright (C) 2015 Sébastien BEAU <sebastien.beau@akretion.com> |
|||
# Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from odoo import api, models |
|||
import requests |
|||
import logging |
|||
import json |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class SmsClient(models.Model): |
|||
_inherit = "sms.gateway" |
|||
|
|||
@api.model |
|||
def get_method(self): |
|||
method = super(SmsClient, self).get_method() |
|||
method.append(('http_ovh', 'OVH HTTP'), ) |
|||
return method |
|||
|
|||
@api.multi |
|||
def _provider_get_provider_conf(self): |
|||
for rec in self: |
|||
keychain = rec.env['keychain.account'] |
|||
if rec._check_permissions: |
|||
retrieve = keychain.suspend_security().retrieve |
|||
else: |
|||
retrieve = keychain.retrieve |
|||
accounts = retrieve( |
|||
[['namespace', '=', 'ovh_provider']]) |
|||
return accounts[0] |
|||
|
|||
|
|||
class SmsSms(models.Model): |
|||
_inherit = "sms.sms" |
|||
|
|||
@api.model |
|||
def _prepare_http_ovh(self): |
|||
|
|||
keychain_account = self.gateway_id._provider_get_provider_conf() |
|||
keychain_json = json.loads(keychain_account['data']) |
|||
params = { |
|||
'smsAccount': keychain_json['sms_account'], |
|||
'login': keychain_account['login'], |
|||
'password': keychain_account.get_password(), |
|||
'from': self.gateway_id.from_provider, |
|||
'url': self.gateway_id.url, |
|||
'to': self._convert_to_e164(self.mobile), |
|||
'message': self.message, |
|||
} |
|||
if self.nostop: |
|||
params['noStop'] = 1 |
|||
if self.deferred: |
|||
params['deferred'] = self.deferred |
|||
if self.classes: |
|||
params['class'] = self.classes |
|||
if self.tag: |
|||
params['tag'] = self.tag |
|||
if self.coding: |
|||
params['smsCoding'] = self.coding |
|||
return params |
|||
|
|||
@api.model |
|||
def _convert_to_e164(self, erp_number): |
|||
to_dial_number = erp_number.replace(u'\xa0', u'') |
|||
return to_dial_number |
|||
|
|||
@api.multi |
|||
def _send_http_ovh(self): |
|||
self.ensure_one() |
|||
params = self._prepare_http_ovh() |
|||
r = requests.get(params['url'], params=params.items()) |
|||
params.update({ |
|||
'password': '*****', |
|||
'to': '*****', |
|||
'smsAccount': '*****', |
|||
'login': '*****', |
|||
}) |
|||
print params |
|||
_logger.debug("Call OVH API : %s params %s", |
|||
params['url'], params) |
|||
response = r.text |
|||
if response[0:2] != 'OK': |
|||
raise ValueError(response) |
@ -1,97 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Module for OpenERP |
|||
# Copyright (C) 2015 Akretion (http://www.akretion.com). |
|||
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
|
|||
from openerp import api, models, _ |
|||
import requests |
|||
import logging |
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class SmsClient(models.Model): |
|||
_inherit = "sms.gateway" |
|||
|
|||
@api.model |
|||
def get_method(self): |
|||
method = super(SmsClient, self).get_method() |
|||
method.append(('http_ovh', 'OVH HTTP'), ) |
|||
return method |
|||
|
|||
@api.onchange('method') |
|||
def onchange_method(self): |
|||
super(SmsClient, self).onchange_method() |
|||
if self.method == 'http_ovh': |
|||
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 |
|||
|
|||
|
|||
class SmsSms(models.Model): |
|||
_inherit = "sms.sms" |
|||
|
|||
@api.model |
|||
def _prepare_http_ovh(self): |
|||
params = { |
|||
'smsAccount': self.gateway_id.sms_account, |
|||
'login': self.gateway_id.login_provider, |
|||
'password': self.gateway_id.password_provider, |
|||
'from': self.gateway_id.from_provider, |
|||
'to': self.mobile, |
|||
'message': self.message, |
|||
} |
|||
if self.nostop: |
|||
params['noStop'] = 1 |
|||
if self.deferred: |
|||
params['deferred'] = self.deferred |
|||
if self.classes: |
|||
params['class'] = self.classes |
|||
if self.tag: |
|||
params['tag'] = self.tag |
|||
if self.coding: |
|||
params['smsCoding'] = self.coding |
|||
return params |
|||
|
|||
@api.multi |
|||
def _send_http_ovh(self): |
|||
self.ensure_one() |
|||
params = self._prepare_http_ovh() |
|||
r = requests.get(self.gateway_id.url, params=params.items()) |
|||
params.update({ |
|||
'password': '*****', |
|||
'to': '*****', |
|||
'smsAccount': '*****', |
|||
'login': '*****', |
|||
}) |
|||
_logger.debug("Call OVH API : %s params %s", |
|||
self.gateway_id.url, params) |
|||
response = r.text |
|||
if response[0:2] != 'OK': |
|||
raise ValueError(response) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue