diff --git a/base_sms_client/__init__.py b/base_sms_client/__init__.py index e4e7434..134df27 100644 --- a/base_sms_client/__init__.py +++ b/base_sms_client/__init__.py @@ -1,7 +1,2 @@ -# -*- coding: utf-8 -*- -# Author: Sébastien BEAU -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - from . import wizard from . import models diff --git a/base_sms_client/__manifest__.py b/base_sms_client/__manifest__.py index 3ddcb4a..93e5d36 100644 --- a/base_sms_client/__manifest__.py +++ b/base_sms_client/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Base Sms Client", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", 'license': 'AGPL-3', "depends": ['mail', 'base_phone', @@ -35,5 +35,5 @@ "wizard/mass_sms_view.xml", "views/smstemplate_view.xml" ], - "installable": False, + "installable": True, } diff --git a/base_sms_client/data/sms_gateway_data.xml b/base_sms_client/data/sms_gateway_data.xml index 4a20fd7..770baef 100644 --- a/base_sms_client/data/sms_gateway_data.xml +++ b/base_sms_client/data/sms_gateway_data.xml @@ -6,7 +6,7 @@ minutes -1 False - sms.gateway + _run_send_sms () False diff --git a/base_sms_client/models/__init__.py b/base_sms_client/models/__init__.py index 7e613da..8831fb3 100644 --- a/base_sms_client/models/__init__.py +++ b/base_sms_client/models/__init__.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2013 Julius Network Solutions SARL -# Author: Sébastien BEAU -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import sms_gateway from . import server_action from . import sms_template diff --git a/base_sms_client/models/server_action.py b/base_sms_client/models/server_action.py index a8eac37..802ddce 100644 --- a/base_sms_client/models/server_action.py +++ b/base_sms_client/models/server_action.py @@ -13,6 +13,10 @@ class ServerAction(models.Model): """ _inherit = 'ir.actions.server' + state = fields.Selection(selection_add=[ + ('sms', 'Send SMS'), + ]) + mobile = fields.Char( string='Mobile No', help="Field to be used to fetch the mobile number, e.g. you select" diff --git a/clicksend_sms_client/__init__.py b/clicksend_sms_client/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/clicksend_sms_client/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/clicksend_sms_client/__manifest__.py b/clicksend_sms_client/__manifest__.py new file mode 100644 index 0000000..7b6fd7e --- /dev/null +++ b/clicksend_sms_client/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2013 Julius Network Solutions SARL +# Copyright (C) 2015 Sébastien BEAU +# Copyright (C) 2019 Eficent Business and IT Consulting Services, S.L. + +{ + 'name': 'ClickSend SMS Client', + 'version': '11.0.1.0.1', + 'license': 'AGPL-3', + 'depends': ['mail', + 'base_sms_client', + 'keychain', + ], + 'author': 'Eficent,' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/connector-telephony', + 'category': 'Tools', + 'data': ['data/keychain.xml'], + 'installable': True, +} diff --git a/clicksend_sms_client/data/keychain.xml b/clicksend_sms_client/data/keychain.xml new file mode 100644 index 0000000..0bb62ab --- /dev/null +++ b/clicksend_sms_client/data/keychain.xml @@ -0,0 +1,9 @@ + + + + ClickSend sms default + clicksend_provider + clicksend_default_account + + + diff --git a/clicksend_sms_client/i18n/ar.po b/clicksend_sms_client/i18n/ar.po new file mode 100644 index 0000000..3dac105 --- /dev/null +++ b/clicksend_sms_client/i18n/ar.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ovh_sms_client +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-27 02:37+0000\n" +"PO-Revision-Date: 2017-04-27 02:37+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Arabic (https://www.transifex.com/oca/teams/23907/ar/)\n" +"Language: ar\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 " +"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_sms +msgid "SMS" +msgstr "رسالة قصيرة (SMS)" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_gateway +msgid "SMS Client" +msgstr "" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_keychain_account +msgid "keychain.account" +msgstr "" diff --git a/clicksend_sms_client/i18n/ca.po b/clicksend_sms_client/i18n/ca.po new file mode 100644 index 0000000..bcb0737 --- /dev/null +++ b/clicksend_sms_client/i18n/ca.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ovh_sms_client +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-27 02:37+0000\n" +"PO-Revision-Date: 2017-04-27 02:37+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_sms +msgid "SMS" +msgstr "SMS" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_gateway +msgid "SMS Client" +msgstr "Client SMS" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_keychain_account +msgid "keychain.account" +msgstr "" diff --git a/clicksend_sms_client/i18n/es.po b/clicksend_sms_client/i18n/es.po new file mode 100644 index 0000000..af49db8 --- /dev/null +++ b/clicksend_sms_client/i18n/es.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ovh_sms_client +# +# Translators: +# OCA Transbot , 2017 +# enjolras , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-10 01:41+0000\n" +"PO-Revision-Date: 2018-02-10 01:41+0000\n" +"Last-Translator: enjolras , 2018\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_sms +msgid "SMS" +msgstr "SMS" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_gateway +msgid "SMS Client" +msgstr "Cliente SMS" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_keychain_account +msgid "keychain.account" +msgstr "keychain.account" diff --git a/clicksend_sms_client/i18n/fr.po b/clicksend_sms_client/i18n/fr.po new file mode 100644 index 0000000..eb5b83a --- /dev/null +++ b/clicksend_sms_client/i18n/fr.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ovh_sms_client +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-27 02:37+0000\n" +"PO-Revision-Date: 2017-04-27 02:37+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_sms +msgid "SMS" +msgstr "SMS" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_gateway +msgid "SMS Client" +msgstr "Client SMS" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_keychain_account +msgid "keychain.account" +msgstr "" diff --git a/clicksend_sms_client/i18n/ovh_sms_client.pot b/clicksend_sms_client/i18n/ovh_sms_client.pot new file mode 100644 index 0000000..72e0113 --- /dev/null +++ b/clicksend_sms_client/i18n/ovh_sms_client.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ovh_sms_client +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_sms +msgid "SMS" +msgstr "" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_sms_gateway +msgid "SMS Client" +msgstr "" + +#. module: ovh_sms_client +#: model:ir.model,name:ovh_sms_client.model_keychain_account +msgid "keychain.account" +msgstr "" + diff --git a/clicksend_sms_client/models/__init__.py b/clicksend_sms_client/models/__init__.py new file mode 100644 index 0000000..d37d138 --- /dev/null +++ b/clicksend_sms_client/models/__init__.py @@ -0,0 +1,2 @@ +from . import sms_gateway +from . import keychain diff --git a/clicksend_sms_client/models/keychain.py b/clicksend_sms_client/models/keychain.py new file mode 100644 index 0000000..03b5ef3 --- /dev/null +++ b/clicksend_sms_client/models/keychain.py @@ -0,0 +1,21 @@ +# Copyright (C) 2015 Sébastien BEAU +# Valentin CHEMIERE +# Copyright (C) 2019 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + +CLICKSEND_KEYCHAIN_NAMESPACE = 'clicksend_provider' + + +class Keychain(models.Model): + _inherit = 'keychain.account' + + namespace = fields.Selection( + selection_add=[(CLICKSEND_KEYCHAIN_NAMESPACE, 'ClickSend_sms')]) + + def _clicksend_provider_init_data(self): + return {'sms_account': ""} + + def _clicksend_provider_validate_data(self, data): + return True diff --git a/clicksend_sms_client/models/sms_gateway.py b/clicksend_sms_client/models/sms_gateway.py new file mode 100644 index 0000000..a0706aa --- /dev/null +++ b/clicksend_sms_client/models/sms_gateway.py @@ -0,0 +1,78 @@ +# Copyright (C) 2015 Sébastien BEAU +# Valentin CHEMIERE +# Copyright (C) 2019 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models, fields +from ..models.keychain import CLICKSEND_KEYCHAIN_NAMESPACE +import requests +import logging +from xml.etree.ElementTree import XML, fromstring, tostring + +_logger = logging.getLogger(__name__) + + +class SmsClient(models.Model): + _inherit = "sms.gateway" + + method = fields.Selection(selection_add=[ + ('http_clicksend', 'ClickSend HTTP')]) + + @api.multi + def _provider_get_provider_conf(self): + for rec in self: + keychain = rec.env['keychain.account'] + # TODO: implement suspend_security module + #if rec._check_permissions(): + # retrieve = keychain.suspend_security().retrieve + #else: + # retrieve = keychain.retrieve + retrieve = keychain.retrieve + accounts = retrieve( + [['namespace', '=', CLICKSEND_KEYCHAIN_NAMESPACE]]) + return accounts[0] + + +class SmsSms(models.Model): + _inherit = "sms.sms" + + @api.model + def _prepare_http_clicksend(self): + + keychain_account = self.gateway_id._provider_get_provider_conf() + params = { + 'username': keychain_account['login'], + 'key': keychain_account.get_password(), + 'senderid': self.gateway_id.from_provider, + 'url': self.gateway_id.url, + 'to': self._convert_to_e164(self.mobile), + 'message': self.message, + } + 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_clicksend(self): + self.ensure_one() + params = self._prepare_http_clicksend() + r = requests.get(params['url'], params=params.items()) + params.update({ + 'password': '*****', + 'to': '*****', + 'smsAccount': '*****', + 'login': '*****', + }) + _logger.debug("Call ClickSend API : %s params %s", + params['url'], params) + response = r.text + xml_response = fromstring(response) + for messages in xml_response: + for message in messages: + for element in message: + if element.tag == 'result' and \ + element.text != '0000': + raise ValueError(response) diff --git a/clicksend_sms_client/readme/CONFIGURE.rst b/clicksend_sms_client/readme/CONFIGURE.rst new file mode 100644 index 0000000..07de988 --- /dev/null +++ b/clicksend_sms_client/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module, you need to: + +* go to settings > technical > telephony > gateway configuration and select ClickSend http in method +* go to settings > technical > keychain and set your credentials diff --git a/clicksend_sms_client/readme/CONTRIBUTORS.rst b/clicksend_sms_client/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..54818cf --- /dev/null +++ b/clicksend_sms_client/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Valentin Chemiere +* Yvan Party +* MonsieurB +* Jordi Ballester Alomar diff --git a/clicksend_sms_client/readme/DESCRIPTION.rst b/clicksend_sms_client/readme/DESCRIPTION.rst new file mode 100644 index 0000000..812a094 --- /dev/null +++ b/clicksend_sms_client/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module provides ClickSend fields to create a ClickSend gateway. \ No newline at end of file