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.

96 lines
3.6 KiB

  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 fields, api, models, _
  23. from openerp.exceptions import Warning
  24. import urllib
  25. import logging
  26. _logger = logging.getLogger(__name__)
  27. try:
  28. from SOAPpy import WSDL
  29. except:
  30. _logger.warning("ERROR IMPORTING SOAPpy, if not installed, please install"
  31. "it: e.g.: apt-get install python-soappy")
  32. class smsclient(models.Model):
  33. _inherit = "sms.smsclient"
  34. @api.model
  35. def get_method(self):
  36. method = super(smsclient, self).get_method()
  37. method.append(('ovh http', 'OVH HTTP'), )
  38. return method
  39. @api.onchange('method')
  40. def onchange_method(self):
  41. super(smsclient, self).onchange_method()
  42. if self.method == 'ovh http':
  43. self.url_visible = True
  44. self.sms_account_visible = True
  45. self.login_provider_visible = True
  46. self.password_provider_visible = True
  47. self.from_provider_visible = True
  48. self.validity_visible = True
  49. self.classes_visible = True
  50. self.deferred_visible = True
  51. self.nostop_visible = True
  52. self.priority_visible = True
  53. self.coding_visible = True
  54. self.tag_visible = True
  55. self.char_limit_visible = True
  56. @api.model
  57. def _send_message(self, data):
  58. super(smsclient, self)._send_message(data)
  59. gateway = data.gateway
  60. if gateway:
  61. if not self._check_permissions(gateway):
  62. raise Warning(_('You have no permission to access %s ')
  63. % (gateway.name,))
  64. url = gateway.url
  65. name = url
  66. if gateway.method == 'http':
  67. prms = {}
  68. prms['smsAccount'] = gateway.sms_account
  69. prms['login'] = gateway.login_provider
  70. prms['password'] = gateway.password_provider
  71. prms['from'] = gateway.from_provider
  72. prms['to'] = data.mobile_to
  73. prms['message'] = data.text
  74. if gateway.nostop:
  75. prms['noStop'] = 1
  76. if gateway.deferred:
  77. prms['deferred'] = gateway.deferred
  78. if gateway.classes:
  79. prms['class'] = gateway.classes
  80. if gateway.tag:
  81. prms['tag'] = gateway.tag
  82. if gateway.coding:
  83. prms['smsCoding'] = gateway.coding
  84. params = urllib.urlencode(prms)
  85. name = url + "?" + params
  86. queue_obj = self.env['sms.smsclient.queue']
  87. vals = self._prepare_smsclient_queue(data, name)
  88. queue_obj.create(vals)
  89. return True