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.

93 lines
3.6 KiB

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