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.

104 lines
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OVH connector module for Odoo
  5. # Copyright (C) 2015 Alexis de Lattre <alexis@via.ecp.fr>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import models, fields, api, _
  22. from openerp.exceptions import UserError
  23. import logging
  24. try:
  25. # -> pip install SOAPpy
  26. from SOAPpy import WSDL
  27. except ImportError:
  28. WSDL = None
  29. _logger = logging.getLogger(__name__)
  30. class ResUsers(models.Model):
  31. _inherit = "res.users"
  32. ovh_billing_number = fields.Char(string='OVH Billing Number')
  33. ovh_calling_number = fields.Char(
  34. string="OVH Calling Number", help="The phone number that will "
  35. "be presented during a click2dial")
  36. ovh_click2call_login = fields.Char(string='OVH Click2call Login')
  37. ovh_click2call_password = fields.Char(
  38. string="OVH Click2call Password")
  39. class PhoneCommon(models.AbstractModel):
  40. _inherit = 'phone.common'
  41. @api.model
  42. def click2dial(self, erp_number):
  43. res = super(PhoneCommon, self).click2dial(erp_number)
  44. if not erp_number:
  45. raise UserError(
  46. _('Missing phone number'))
  47. user = self.env.user
  48. if not user.ovh_billing_number:
  49. raise UserError(
  50. _('Missing OVH Billing Number on user %s') % user.name)
  51. if not user.ovh_calling_number:
  52. raise UserError(
  53. _('Missing OVH Calling Number on user %s') % user.name)
  54. if not user.ovh_click2call_login:
  55. raise UserError(
  56. _('Missing OVH Click2call Login on user %s') % user.name)
  57. if not user.ovh_click2call_password:
  58. raise UserError(
  59. _('Missing OVH Click2dial Password on user %s') % user.name)
  60. soap = WSDL.Proxy('https://www.ovh.com/soapi/soapi-re-1.63.wsdl')
  61. called_number = self.convert_to_dial_number(erp_number)
  62. _logger.debug(
  63. 'Starting OVH telephonyClick2CallDo request with '
  64. 'login = %s billing number = %s calling number = %s '
  65. 'and called_number = %s',
  66. user.ovh_click2call_login, user.ovh_billing_number,
  67. user.ovh_calling_number, called_number)
  68. try:
  69. soap.telephonyClick2CallDo(
  70. user.ovh_click2call_login,
  71. user.ovh_click2call_password,
  72. user.ovh_calling_number,
  73. called_number,
  74. user.ovh_billing_number)
  75. _logger.info("OVH telephonyClick2CallDo successfull")
  76. except Exception, e:
  77. _logger.error(
  78. "Error in the OVH telephonyClick2CallDo request")
  79. _logger.error(
  80. "Here are the details of the error: '%s'", unicode(e))
  81. raise UserError(
  82. _("Click to call to OVH failed.\nHere is the error: "
  83. "'%s'")
  84. % unicode(e))
  85. res['dialed_number'] = called_number
  86. return res