Browse Source

Mig to 10 with keychain password tool

pull/128/head
MonsieurB 8 years ago
parent
commit
0ba9fbfc1c
  1. 2
      smsclient_core/models/serveraction.py
  2. 84
      smsclient_core/models/sms_gateway.py
  3. 2
      smsclient_core/models/smstemplate.py
  4. 37
      smsclient_core/views/sms_gateway_view.xml
  5. 23
      smsclient_core/wizard/mass_sms.py
  6. 13
      smsclient_ovh/README.rst
  7. 27
      smsclient_ovh/__init__.py
  8. 32
      smsclient_ovh/__manifest__.py
  9. 49
      smsclient_ovh/__openerp__.py
  10. 9
      smsclient_ovh/data/keychain.xml
  11. 7
      smsclient_ovh/models/__init__.py
  12. 45
      smsclient_ovh/models/keychain.py
  13. 86
      smsclient_ovh/models/sms_gateway.py
  14. 97
      smsclient_ovh/sms_gateway.py

2
smsclient_core/models/serveraction.py

@ -28,5 +28,5 @@ class ServerAction(models.Model):
comodel_name='sms.gateway', string='SMS Server', comodel_name='sms.gateway', string='SMS Server',
help='Select the SMS Gateway configuration to use with this action.') help='Select the SMS Gateway configuration to use with this action.')
sms_template_id = fields.Many2one( sms_template_id = fields.Many2one(
comodel_name='email.template', string='SMS Template',
comodel_name='mail.template', string='SMS Template',
help='Select the SMS Template configuration to use with this action.') help='Select the SMS Template configuration to use with this action.')

84
smsclient_core/models/sms_gateway.py

@ -8,7 +8,7 @@
import logging import logging
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from functools import wraps
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -26,6 +26,7 @@ CLASSES_LIST = [
('3', 'Toolkit') ('3', 'Toolkit')
] ]
class SMSClient(models.Model): class SMSClient(models.Model):
_name = 'sms.gateway' _name = 'sms.gateway'
_description = 'SMS Client' _description = 'SMS Client'
@ -34,41 +35,13 @@ class SMSClient(models.Model):
def get_method(self): def get_method(self):
return [] return []
@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', '=', 'SMS_Gateway%s' % rec.provider_type]])
return accounts[0]
# @api.multi
# def _get_provider_conf(self):
# for sms_provider in self:
# global_section_name = 'sms_provider'
# config_vals = {}
# if serv_config.has_section(global_section_name):
# config_vals.update(serv_config.items(global_section_name))
# custom_section_name = '.'.join((global_section_name,
# sms_provider.name))
# if serv_config.has_section(custom_section_name):
# config_vals.update(serv_config.items(custom_section_name))
# for key in config_vals:
# sms_provider[key] = config_vals[key]
name = fields.Char(string='Gateway Name', required=True) name = fields.Char(string='Gateway Name', required=True)
url = fields.Char(
string='Gateway URL', compute='_get_provider_conf',
help='Base url for message')
url_visible = fields.Boolean(default=False)
from_provider = fields.Char(string="From")
method = fields.Selection( method = fields.Selection(
string='API Method', string='API Method',
selection='get_method') selection='get_method')
url = fields.Char(
string='Gateway URL', help='Base url for message')
state = fields.Selection(selection=[ state = fields.Selection(selection=[
('new', 'Not Verified'), ('new', 'Not Verified'),
('waiting', 'Waiting for Verification'), ('waiting', 'Waiting for Verification'),
@ -77,16 +50,7 @@ class SMSClient(models.Model):
user_ids = fields.Many2many( user_ids = fields.Many2many(
comodel_name='res.users', comodel_name='res.users',
string='Users Allowed') string='Users Allowed')
sms_account = fields.Char(compute='_get_provider_conf')
sms_account_visible = fields.Boolean(default=False)
login_provider = fields.Char(compute='_get_provider_conf')
login_provider_visible = fields.Boolean(default=False)
password_provider = fields.Char(compute='_get_provider_conf')
password_provider_visible = fields.Boolean(default=False)
from_provider = fields.Char(compute='_get_provider_conf')
from_provider_visible = fields.Boolean(default=False)
code = fields.Char('Verification Code') code = fields.Char('Verification Code')
code_visible = fields.Boolean(default=False)
body = fields.Text( body = fields.Text(
string='Message', string='Message',
help="The message text that will be send along with the" help="The message text that will be send along with the"
@ -95,12 +59,10 @@ class SMSClient(models.Model):
default=10, default=10,
help="The maximum time - in minute(s) - before the message " help="The maximum time - in minute(s) - before the message "
"is dropped.") "is dropped.")
validity_visible = fields.Boolean(default=False)
classes = fields.Selection( classes = fields.Selection(
selection=CLASSES_LIST, string='Class', selection=CLASSES_LIST, string='Class',
default='1', default='1',
help='The SMS class: flash(0),phone display(1),SIM(2),toolkit(3)') help='The SMS class: flash(0),phone display(1),SIM(2),toolkit(3)')
classes_visible = fields.Boolean(default=False)
deferred = fields.Integer( deferred = fields.Integer(
default=0, default=0,
help='The time -in minute(s)- to wait before sending the message.') help='The time -in minute(s)- to wait before sending the message.')
@ -108,7 +70,6 @@ class SMSClient(models.Model):
priority = fields.Selection( priority = fields.Selection(
selection=PRIORITY_LIST, string='Priority', default='3', selection=PRIORITY_LIST, string='Priority', default='3',
help='The priority of the message') help='The priority of the message')
priority_visible = fields.Boolean(default=False)
coding = fields.Selection(selection=[ coding = fields.Selection(selection=[
('1', '7 bit'), ('1', '7 bit'),
('2', 'Unicode') ('2', 'Unicode')
@ -118,36 +79,15 @@ class SMSClient(models.Model):
'lenght)', 'lenght)',
default='1' default='1'
) )
coding_visible = fields.Boolean(default=False)
tag = fields.Char('Tag', help='an optional tag') tag = fields.Char('Tag', help='an optional tag')
tag_visible = fields.Boolean(default=False)
nostop = fields.Boolean( nostop = fields.Boolean(
default=True, default=True,
help='Do not display STOP clause in the message, this requires that ' help='Do not display STOP clause in the message, this requires that '
'this is not an advertising message.') 'this is not an advertising message.')
nostop_visible = fields.Boolean(default=False)
char_limit = fields.Boolean('Character Limit', default=True) char_limit = fields.Boolean('Character Limit', default=True)
char_limit_visible = fields.Boolean(default=False)
default_gateway = fields.Boolean(default=False) default_gateway = fields.Boolean(default=False)
company_id = fields.Many2one(comodel_name='res.company') company_id = fields.Many2one(comodel_name='res.company')
@api.onchange('method')
def onchange_method(self):
if not self.method:
self.url_visible = False
self.sms_account_visible = False
self.login_provider_visible = False
self.password_provider_visible = False
self.from_provider_visible = False
self.validity_visible = False
self.classes_visible = False
self.deferred_visible = False
self.nostop_visible = False
self.priority_visible = False
self.coding_visible = False
self.tag_visible = False
self.char_limit_visible = False
@api.multi @api.multi
def _check_permissions(self): def _check_permissions(self):
self.ensure_one() self.ensure_one()
@ -189,7 +129,6 @@ class SmsSms(models.Model):
('cancel', 'Cancel'), ('cancel', 'Cancel'),
('error', 'Error'), ('error', 'Error'),
], string='Message Status', ], string='Message Status',
select=True,
readonly=True, readonly=True,
default='draft') default='draft')
error = fields.Text( error = fields.Text(
@ -243,6 +182,11 @@ class SmsSms(models.Model):
readonly=True, readonly=True,
states={'draft': [('readonly', False)]}) states={'draft': [('readonly', False)]})
@api.model
def _convert_to_e164(self, erp_number):
to_dial_number = erp_number.replace(u'\xa0', u' ')
return to_dial_number
@api.onchange('partner_id') @api.onchange('partner_id')
def onchange_partner_id(self): def onchange_partner_id(self):
self.mobile = self.partner_id.mobile self.mobile = self.partner_id.mobile
@ -250,13 +194,19 @@ class SmsSms(models.Model):
@api.multi @api.multi
def send(self): def send(self):
for sms in self: for sms in self:
if not sms.gateway_id._check_permissions():
sms.write(
{'error': 'no permission on gateway', 'state': 'error'})
sms._cr.commit()
return False
if sms.gateway_id.char_limit and len(sms.message) > 160: if sms.gateway_id.char_limit and len(sms.message) > 160:
sms.write({ sms.write({
'state': 'error', 'state': 'error',
'error': _('Size of SMS should not be more then 160 char'), 'error': _('Size of SMS should not be more then 160 char'),
}) })
if not hasattr(sms, "_send_%s" % sms.gateway_id.method): if not hasattr(sms, "_send_%s" % sms.gateway_id.method):
raise NotImplemented
#may not exist the gateway
raise UserError(_("No method gateway selected"))
else: else:
try: try:
with sms._cr.savepoint(): with sms._cr.savepoint():

2
smsclient_core/models/smstemplate.py

@ -8,7 +8,7 @@
from odoo import models, fields from odoo import models, fields
class email_template(models.Model):
class mail_template(models.Model):
_inherit = "mail.template" _inherit = "mail.template"
sms_template = fields.Boolean('SMS Template') sms_template = fields.Boolean('SMS Template')

37
smsclient_core/views/sms_gateway_view.xml

@ -19,17 +19,9 @@
<notebook colspan="4"> <notebook colspan="4">
<page string="General"> <page string="General">
<group col="4"> <group col="4">
<field name="url" colspan="4" attrs="{'invisible': [('url_visible', '=', False),]}"/>
<field name="url_visible" invisible="1"/>
<field name="sms_account" attrs="{'invisible': [('sms_account_visible', '=', False),]}"/>
<field name="sms_account_visible" invisible="1"/>
<field name="login_provider" attrs="{'invisible': [('login_provider_visible', '=', False),]}"/>
<field name="login_provider_visible" invisible="1"/>
<field name="password_provider" attrs="{'invisible': [('password_provider_visible', '=', False),]}"/>
<field name="password_provider_visible" invisible="1"/>
<field name="from_provider" attrs="{'invisible': [('from_provider_visible', '=', False),]}"/>
<field name="from_provider_visible" invisible="1"/>
<field name="state"/> <field name="state"/>
<field name="from_provider"/>
<field name="url"/>
</group> </group>
</page> </page>
<page string="Permission"> <page string="Permission">
@ -40,24 +32,16 @@
<page string="Additional option"> <page string="Additional option">
<group> <group>
<group> <group>
<field name="validity" attrs="{'invisible': [('validity_visible', '=', False),]}"/>
<field name="validity_visible" invisible="1"/>
<field name="classes" attrs="{'invisible': [('classes_visible', '=', False),]}"/>
<field name="classes_visible" invisible="1"/>
<field name="deferred" attrs="{'invisible': [('deferred_visible', '=', False),]}"/>
<field name="deferred_visible" invisible="1"/>
<field name="nostop" attrs="{'invisible': [('nostop_visible', '=', False),]}"/>
<field name="nostop_visible" invisible="1"/>
<field name="validity" />
<field name="classes"/>
<field name="deferred" />
<field name="nostop" />
</group> </group>
<group> <group>
<field name="priority" attrs="{'invisible': [('priority_visible', '=', False),]}"/>
<field name="priority_visible" invisible="1"/>
<field name="coding" attrs="{'invisible': [('coding_visible', '=', False),]}"/>
<field name="coding_visible" invisible="1"/>
<field name="tag" attrs="{'invisible': [('tag_visible', '=', False),]}"/>
<field name="tag_visible" invisible="1"/>
<field name="char_limit" attrs="{'invisible': [('char_limit_visible', '=', False),]}"/>
<field name="char_limit_visible" invisible="1"/>
<field name="priority" />
<field name="coding"/>
<field name="tag"/>
<field name="char_limit"/>
</group> </group>
</group> </group>
</page> </page>
@ -74,7 +58,6 @@
<tree string="SMS Gateways"> <tree string="SMS Gateways">
<field name="name"/> <field name="name"/>
<field name="method"/> <field name="method"/>
<field name="url"/>
</tree> </tree>
</field> </field>
</record> </record>

23
smsclient_core/wizard/mass_sms.py

@ -1,23 +1,8 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>)
# coding: utf-8
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.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/>
#
##############################################################################
# Copyright (C) 2015 Valentin Chemiere <valentin.chemiere@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields, api from odoo import models, fields, api

13
smsclient_ovh/README.rst

@ -1,8 +1,9 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3 :alt: License: AGPL-3
===============
SMS client OVH SMS client OVH
===========
===============
This module provide OVH fields to create OVH gateway. This module provide OVH fields to create OVH gateway.
@ -11,16 +12,13 @@ Usage
To use this module, you need to: To use this module, you need to:
* go to gateway configuration and select OVH http in method
* go to settings > technical > telephony >gateway configuration and select OVH http in method
* go to settings > technical > keychain and set your credentials
For further information, please visit: For further information, please visit:
* https://www.odoo.com/forum/help-1 * https://www.odoo.com/forum/help-1
Known issues / Roadmap
======================
* ...
Bug Tracker Bug Tracker
=========== ===========
@ -37,8 +35,9 @@ Credits
Contributors Contributors
------------ ------------
* Valentin Chemiere <valentin.chemiere@akretion.com>
* Valentin Chemiere
* Yvan Party <yvan@julius.fr> * Yvan Party <yvan@julius.fr>
* MonsieurB <monsieurb@saaslys.com>
Maintainer Maintainer
---------- ----------

27
smsclient_ovh/__init__.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

32
smsclient_ovh/__manifest__.py

@ -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:

49
smsclient_ovh/__openerp__.py

@ -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:

9
smsclient_ovh/data/keychain.xml

@ -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>

7
smsclient_ovh/models/__init__.py

@ -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

45
smsclient_ovh/models/keychain.py

@ -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

86
smsclient_ovh/models/sms_gateway.py

@ -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)

97
smsclient_ovh/sms_gateway.py

@ -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)
Loading…
Cancel
Save