Add a field 'resource' on res.users, which is used in "SIP/resource", instead of "SIP/internal_number", which was not correct. YOU NEED TO UPDATE YOUR DATA !
# Lib for phone number reformating -> pip install phonenumbers
importphonenumbers
# Lib py-asterisk from http://code.google.com/p/py-asterisk/
# We need a version which has this commit : http://code.google.com/p/py-asterisk/source/detail?r=8d0e1c941cce727c702582f3c9fcd49beb4eeaa4
# so a version after Nov 20th, 2012
fromAsteriskimportManager
_logger=logging.getLogger(__name__)
@ -49,7 +53,7 @@ class asterisk_server(osv.osv):
'context':fields.char('Dialplan context',size=50,required=True,help="Asterisk dialplan context from which the calls will be made. Refer to /etc/asterisk/extensions.conf on your Asterisk server."),
'wait_time':fields.integer('Wait time (sec)',required=True,help="Amount of time (in seconds) Asterisk will try to reach the user's phone before hanging up."),
'extension_priority':fields.integer('Extension priority',required=True,help="Priority of the extension in the Asterisk dialplan. Refer to /etc/asterisk/extensions.conf on your Asterisk server."),
'alert_info':fields.char('Alert-Info SIP header',size=255,help="Set Alert-Info header in SIP request to user's IP Phone for the click2dial feature. If empty, the Alert-Info header will not be added. You can use it to have a special ring tone for click2dial (a silent one !) or to activate auto-answer for example. If you want to have several variable headers, separate them with '|'."),
'alert_info':fields.char('Alert-Info SIP header',size=255,help="Set Alert-Info header in SIP request to user's IP Phone for the click2dial feature. If empty, the Alert-Info header will not be added. You can use it to have a special ring tone for click2dial (a silent one !) or to activate auto-answer for example."),
'company_id':fields.many2one('res.company','Company',help="Company who uses the Asterisk server."),
}
@ -188,28 +192,10 @@ class asterisk_server(osv.osv):
_logger.debug('Successfull logout from Asterisk :\n%s'%logout_answer)
else:
_logger.warning('Logout from Asterisk failed :\n%s'%logout_answer)
# we catch only network problems here
exceptsocket.error:
_logger.warning("Unable to connect to the Asterisk server '%s' IP '%s:%d'"%(ast_server.name,ast_server.ip_address,ast_server.port))
raiseosv.except_osv(_('Error :'),_("The connection from OpenERP to the Asterisk server failed. Please check the configuration on OpenERP and on Asterisk."))
finally:
sock.close()
ifmethod=='dial':
_logger.info("Asterisk Click2Dial from %s/%s to %s"%(user.asterisk_chan_type,user.internal_number,ast_number))
returnTrue
ast_manager.Logoff()
_logger.debug("The calling party number is '%s'"%calling_party_number)
elifmethod=="get_calling_number":
returncalling_party_number
else:
returnFalse
asterisk_server()
@ -372,7 +330,9 @@ class res_users(osv.osv):
('SCCP','SCCP'),
],'Asterisk channel type',
help="Asterisk channel type, as used in the Asterisk dialplan. If the user has a regular IP phone, the channel type is 'SIP'."),
'alert_info':fields.char('User-specific Alert-Info SIP header',size=255,help="Set a user-specific Alert-Info header in SIP request to user's IP Phone for the click2dial feature. If empty, the Alert-Info header will not be added. You can use it to have a special ring tone for click2dial (a silent one !) or to activate auto-answer for example. If you want to have several variable headers, separate them with '|'."),
'resource':fields.char('Resource name',size=64,
help="Resource name for the channel type selected. For example, if you use 'Dial(SIP/phone1)' in your Asterisk dialplan to ring the SIP phone of this user, then the resource name for this user is 'phone1'. For a SIP phone, the phone number is often used as resource name, but not always."),
'alert_info':fields.char('User-specific Alert-Info SIP header',size=255,help="Set a user-specific Alert-Info header in SIP request to user's IP Phone for the click2dial feature. If empty, the Alert-Info header will not be added. You can use it to have a special ring tone for click2dial (a silent one !) or to activate auto-answer for example."),
'variable':fields.char('User-specific Variable',size=255,help="Set a user-specific 'Variable' field in the Asterisk Manager Interface 'originate' request for the click2dial feature. If you want to have several variable headers, separate them with '|'."),
help="Asterisk server on which the user's phone is connected. If you leave this field empty, it will use the first Asterisk server of the user's company."),
(_check_validity,"Error message in raise",['internal_number','callerid']),
(_check_validity,"Error message in raise",['resource','internal_number','callerid']),
]
res_users()
@ -481,8 +441,7 @@ class res_partner_address(osv.osv):
raiseosv.except_osv(_('Error :'),_('There is no phone number !'))
eliferp_number_displayandnoterp_number_e164:
raiseosv.except_osv(_('Error :'),_("The phone number isn't stored in the standard E.164 format. Try to run the wizard 'Reformat all phone numbers' from the menu Settings > Configuration > Asterisk."))