You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.2 KiB

10 years ago
  1. # -*- coding: utf-8 -*-
  2. ###############################################################################
  3. #
  4. # Module for OpenERP
  5. # Copyright (C) 2015 Akretion (http://www.akretion.com).
  6. # @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###############################################################################
  22. from openerp import api, models, _
  23. import requests
  24. import logging
  25. _logger = logging.getLogger(__name__)
  26. class SmsClient(models.Model):
  27. _inherit = "sms.gateway"
  28. @api.model
  29. def get_method(self):
  30. method = super(SmsClient, self).get_method()
  31. method.append(('http_ovh', 'OVH HTTP'), )
  32. return method
  33. @api.onchange('method')
  34. def onchange_method(self):
  35. super(SmsClient, self).onchange_method()
  36. if self.method == 'http_ovh':
  37. self.url_visible = True
  38. self.sms_account_visible = True
  39. self.login_provider_visible = True
  40. self.password_provider_visible = True
  41. self.from_provider_visible = True
  42. self.validity_visible = True
  43. self.classes_visible = True
  44. self.deferred_visible = True
  45. self.nostop_visible = True
  46. self.priority_visible = True
  47. self.coding_visible = True
  48. self.tag_visible = True
  49. self.char_limit_visible = True
  50. class SmsSms(models.Model):
  51. _inherit = "sms.sms"
  52. @api.model
  53. def _prepare_http_ovh(self):
  54. params = {
  55. 'smsAccount': self.gateway_id.sms_account,
  56. 'login': self.gateway_id.login_provider,
  57. 'password': self.gateway_id.password_provider,
  58. 'from': self.gateway_id.from_provider,
  59. 'to': self.mobile,
  60. 'message': self.message,
  61. }
  62. if self.nostop:
  63. params['noStop'] = 1
  64. if self.deferred:
  65. params['deferred'] = self.deferred
  66. if self.classes:
  67. params['class'] = self.classes
  68. if self.tag:
  69. params['tag'] = self.tag
  70. if self.coding:
  71. params['smsCoding'] = self.coding
  72. return params
  73. @api.multi
  74. def _send_http_ovh(self):
  75. self.ensure_one()
  76. params = self._prepare_http_ovh().items()
  77. r = requests.get(self.gateway_id.url, params=params)
  78. params['password'] = '*****'
  79. _logger.debug("Call OVH API : %s params %s",
  80. self.gateway_id.url, params)
  81. response = r.text
  82. if response[0:2] != 'OK':
  83. raise ValueError(response)