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.

109 lines
4.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models, fields, api, _
  5. from odoo.exceptions import UserError, ValidationError
  6. class ResUsers(models.Model):
  7. _inherit = "res.users"
  8. internal_number = fields.Char(
  9. string='Internal Number', copy=False,
  10. help="User's internal phone number.")
  11. dial_suffix = fields.Char(
  12. string='User-specific Dial Suffix',
  13. help="User-specific dial suffix such as aa=2wb for SCCP auto answer.")
  14. callerid = fields.Char(
  15. string='Caller ID', copy=False,
  16. help="Caller ID used for the calls initiated by this user.")
  17. # You'd probably think: Asterisk should reuse the callerID of sip.conf!
  18. # But it cannot, cf
  19. # http://lists.digium.com/pipermail/asterisk-users/
  20. # 2012-January/269787.html
  21. cdraccount = fields.Char(
  22. string='CDR Account',
  23. help="Call Detail Record (CDR) account used for billing this user.")
  24. asterisk_chan_type = fields.Selection([
  25. ('SIP', 'SIP'),
  26. ('PJSIP', 'PJSIP'),
  27. ('IAX2', 'IAX2'),
  28. ('DAHDI', 'DAHDI'),
  29. ('Zap', 'Zap'),
  30. ('Skinny', 'Skinny'),
  31. ('MGCP', 'MGCP'),
  32. ('mISDN', 'mISDN'),
  33. ('H323', 'H323'),
  34. ('SCCP', 'SCCP'),
  35. # Local works for click2dial, but it won't work in
  36. # _get_calling_number() when trying to identify the
  37. # channel of the user, so it's better not to propose it
  38. # ('Local', 'Local'),
  39. ], string='Asterisk Channel Type', default='SIP',
  40. help="Asterisk channel type, as used in the Asterisk dialplan. "
  41. "If the user has a regular IP phone, the channel type is 'SIP'.")
  42. resource = fields.Char(
  43. string='Resource Name', copy=False,
  44. help="Resource name for the channel type selected. For example, "
  45. "if you use 'Dial(SIP/phone1)' in your Asterisk dialplan to ring "
  46. "the SIP phone of this user, then the resource name for this user "
  47. "is 'phone1'. For a SIP phone, the phone number is often used as "
  48. "resource name, but not always.")
  49. alert_info = fields.Char(
  50. string='User-specific Alert-Info SIP Header',
  51. help="Set a user-specific Alert-Info header in SIP request to "
  52. "user's IP Phone for the click2dial feature. If empty, the "
  53. "Alert-Info header will not be added. You can use it to have a "
  54. "special ring tone for click2dial (a silent one !) or to "
  55. "activate auto-answer for example.")
  56. variable = fields.Char(
  57. string='User-specific Variable',
  58. help="Set a user-specific 'Variable' field in the Asterisk "
  59. "Manager Interface 'originate' request for the click2dial "
  60. "feature. If you want to have several variable headers, separate "
  61. "them with '|'.")
  62. asterisk_server_id = fields.Many2one(
  63. 'asterisk.server', string='Asterisk Server',
  64. help="Asterisk server on which the user's phone is connected. "
  65. "If you leave this field empty, it will use the first Asterisk "
  66. "server of the user's company.")
  67. @api.multi
  68. @api.constrains('resource', 'internal_number', 'callerid')
  69. def _check_validity(self):
  70. for user in self:
  71. strings_to_check = [
  72. (_('Resource Name'), user.resource),
  73. (_('Internal Number'), user.internal_number),
  74. (_('Caller ID'), user.callerid),
  75. ]
  76. for check_string in strings_to_check:
  77. if check_string[1]:
  78. try:
  79. check_string[1].encode('ascii')
  80. except UnicodeEncodeError:
  81. raise ValidationError(_(
  82. "The '%s' for the user '%s' should only have "
  83. "ASCII caracters")
  84. % (check_string[0], user.name))
  85. @api.multi
  86. def get_asterisk_server_from_user(self):
  87. '''Returns an asterisk.server recordset'''
  88. self.ensure_one()
  89. # We check if the user has an Asterisk server configured
  90. if self.asterisk_server_id:
  91. ast_server = self.asterisk_server_id
  92. else:
  93. asterisk_servers = self.env['asterisk.server'].search(
  94. [('company_id', '=', self.company_id.id)])
  95. # If the user doesn't have an asterisk server,
  96. # we take the first one of the user's company
  97. if not asterisk_servers:
  98. raise UserError(
  99. _("No Asterisk server configured for the company '%s'.")
  100. % self.company_id.name)
  101. else:
  102. ast_server = asterisk_servers[0]
  103. return ast_server