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.

108 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. ('IAX2', 'IAX2'),
  27. ('DAHDI', 'DAHDI'),
  28. ('Zap', 'Zap'),
  29. ('Skinny', 'Skinny'),
  30. ('MGCP', 'MGCP'),
  31. ('mISDN', 'mISDN'),
  32. ('H323', 'H323'),
  33. ('SCCP', 'SCCP'),
  34. # Local works for click2dial, but it won't work in
  35. # _get_calling_number() when trying to identify the
  36. # channel of the user, so it's better not to propose it
  37. # ('Local', 'Local'),
  38. ], string='Asterisk Channel Type', default='SIP',
  39. help="Asterisk channel type, as used in the Asterisk dialplan. "
  40. "If the user has a regular IP phone, the channel type is 'SIP'.")
  41. resource = fields.Char(
  42. string='Resource Name', copy=False,
  43. help="Resource name for the channel type selected. For example, "
  44. "if you use 'Dial(SIP/phone1)' in your Asterisk dialplan to ring "
  45. "the SIP phone of this user, then the resource name for this user "
  46. "is 'phone1'. For a SIP phone, the phone number is often used as "
  47. "resource name, but not always.")
  48. alert_info = fields.Char(
  49. string='User-specific Alert-Info SIP Header',
  50. help="Set a user-specific Alert-Info header in SIP request to "
  51. "user's IP Phone for the click2dial feature. If empty, the "
  52. "Alert-Info header will not be added. You can use it to have a "
  53. "special ring tone for click2dial (a silent one !) or to "
  54. "activate auto-answer for example.")
  55. variable = fields.Char(
  56. string='User-specific Variable',
  57. help="Set a user-specific 'Variable' field in the Asterisk "
  58. "Manager Interface 'originate' request for the click2dial "
  59. "feature. If you want to have several variable headers, separate "
  60. "them with '|'.")
  61. asterisk_server_id = fields.Many2one(
  62. 'asterisk.server', string='Asterisk Server',
  63. help="Asterisk server on which the user's phone is connected. "
  64. "If you leave this field empty, it will use the first Asterisk "
  65. "server of the user's company.")
  66. @api.multi
  67. @api.constrains('resource', 'internal_number', 'callerid')
  68. def _check_validity(self):
  69. for user in self:
  70. strings_to_check = [
  71. (_('Resource Name'), user.resource),
  72. (_('Internal Number'), user.internal_number),
  73. (_('Caller ID'), user.callerid),
  74. ]
  75. for check_string in strings_to_check:
  76. if check_string[1]:
  77. try:
  78. check_string[1].encode('ascii')
  79. except UnicodeEncodeError:
  80. raise ValidationError(_(
  81. "The '%s' for the user '%s' should only have "
  82. "ASCII caracters")
  83. % (check_string[0], user.name))
  84. @api.multi
  85. def get_asterisk_server_from_user(self):
  86. '''Returns an asterisk.server recordset'''
  87. self.ensure_one()
  88. # We check if the user has an Asterisk server configured
  89. if self.asterisk_server_id:
  90. ast_server = self.asterisk_server_id
  91. else:
  92. asterisk_servers = self.env['asterisk.server'].search(
  93. [('company_id', '=', self.company_id.id)])
  94. # If the user doesn't have an asterisk server,
  95. # we take the first one of the user's company
  96. if not asterisk_servers:
  97. raise UserError(
  98. _("No Asterisk server configured for the company '%s'.")
  99. % self.company_id.name)
  100. else:
  101. ast_server = asterisk_servers[0]
  102. return ast_server