- now parses answers received from Asterisk and display errors to the user
- now properly encodes the requests sent to Asterisk in ASCII (AMI doesn't support other charsets unfortunately)
- required fields are now required=True
- Single constraint function for all asterisk.server fields
- Fields that shouldn't have non-ascii caracters are not validated if they have non-ASCII caracters (including CallerID)
- clean-up error message code
- if no Asterisk server is defined for a user, it takes the first Asterisk serve
r defined
- methods now always return something
# Copyright (C) 2010 Alexis de Lattre <alexis@via.ecp.fr>
# Copyright (C) 2010-2012 Alexis de Lattre <alexis@via.ecp.fr>
#
#
# This program is free software: you can redistribute it and/or modify
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# it under the terms of the GNU Affero General Public License as
@ -41,7 +41,7 @@ class asterisk_server(osv.osv):
'port':fields.integer('Port',required=True,help="TCP port on which the Asterisk Manager Interface listens. Defined in /etc/asterisk/manager.conf on Asterisk."),
'port':fields.integer('Port',required=True,help="TCP port on which the Asterisk Manager Interface listens. Defined in /etc/asterisk/manager.conf on Asterisk."),
'out_prefix':fields.char('Out prefix',size=4,help="Prefix to dial to place outgoing calls. If you don't use a prefix to place outgoing calls, leave empty."),
'out_prefix':fields.char('Out prefix',size=4,help="Prefix to dial to place outgoing calls. If you don't use a prefix to place outgoing calls, leave empty."),
'national_prefix':fields.char('National prefix',size=4,help="Prefix for national phone calls (don't include the 'out prefix'). For e.g., in France, the phone numbers look like '01 41 98 12 42' : the National prefix is '0'."),
'national_prefix':fields.char('National prefix',size=4,help="Prefix for national phone calls (don't include the 'out prefix'). For e.g., in France, the phone numbers look like '01 41 98 12 42' : the National prefix is '0'."),
'international_prefix':fields.char('International prefix',size=4,help="Prefix to add to make international phone calls (don't include the 'out prefix'). For e.g., in France, the International prefix is '00'."),
'international_prefix':fields.char('International prefix',required=True,size=4,help="Prefix to add to make international phone calls (don't include the 'out prefix'). For e.g., in France, the International prefix is '00'."),
'country_prefix':fields.char('My country prefix',required=True,size=4,help="Phone prefix of the country where the Asterisk server is located. For e.g. the phone prefix for France is '33'. If the phone number to dial starts with the 'My country prefix', OpenERP will remove the country prefix from the phone number and add the 'out prefix' followed by the 'national prefix'. If the phone number to dial doesn't start with the 'My country prefix', OpenERP will add the 'out prefix' followed by the 'international prefix'."),
'country_prefix':fields.char('My country prefix',required=True,size=4,help="Phone prefix of the country where the Asterisk server is located. For e.g. the phone prefix for France is '33'. If the phone number to dial starts with the 'My country prefix', OpenERP will remove the country prefix from the phone number and add the 'out prefix' followed by the 'national prefix'. If the phone number to dial doesn't start with the 'My country prefix', OpenERP will add the 'out prefix' followed by the 'international prefix'."),
'national_format_allowed':fields.boolean('National format allowed ?',help="Do we allow to use click2dial on phone numbers written in national format, e.g. 01 41 98 12 42, or only in the international format, e.g. +33 1 41 98 12 42 ?"),
'national_format_allowed':fields.boolean('National format allowed ?',help="Do we allow to use click2dial on phone numbers written in national format, e.g. 01 41 98 12 42, or only in the international format, e.g. +33 1 41 98 12 42 ?"),
'login':fields.char('AMI login',size=30,required=True,help="Login that OpenERP will use to communicate with the Asterisk Manager Interface. Refer to /etc/asterisk/manager.conf on your Asterisk server."),
'login':fields.char('AMI login',size=30,required=True,help="Login that OpenERP will use to communicate with the Asterisk Manager Interface. Refer to /etc/asterisk/manager.conf on your Asterisk server."),
@ -63,60 +63,37 @@ class asterisk_server(osv.osv):
(_only_digits_out_prefix,"Only use digits for the 'out prefix' or leave empty",['out_prefix']),
(_only_digits_country_prefix,"Only use digits for the 'country prefix'",['country_prefix']),
(_only_digits_national_prefix,"Only use digits for the 'national prefix' or leave empty",['national_prefix']),
(_only_digits_international_prefix,"Only use digits for 'international prefix'",['international_prefix']),
(_check_wait_time,"You should enter a 'Wait time' value between 1 and 120 seconds",['wait_time']),
(_check_extension_priority,"The 'extension priority' must be a positive value",['extension_priority']),
(_check_port,'TCP ports range from 1 to 65535',['port']),
(_check_validity,"Error message in raise",['out_prefix','country_prefix','national_prefix','international_prefix','wait_time','extension_priority','port','context','alert_info','login','password']),
]
]
@ -137,15 +114,15 @@ class asterisk_server(osv.osv):
# Let's call the variable tmp_number now
# Let's call the variable tmp_number now
tmp_number=erp_number
tmp_number=erp_number
logger.notifyChannel('asterisk_click2dial',netsvc.LOG_DEBUG,'Number before reformat = '+tmp_number)
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Number before reformat = %s'%tmp_number)
logger.notifyChannel('asterisk_click2dial',netsvc.LOG_DEBUG,'National prefix = '+national_prefix+' - Number with national prefix = '+tmp_number)
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'National prefix = %s - Number with national prefix = %s'%(national_prefix,tmp_number))
else:
else:
# If the number is an international number,
# If the number is an international number,
# add 'international prefix'
# add 'international prefix'
tmp_number=international_prefix+tmp_number
tmp_number=international_prefix+tmp_number
logger.notifyChannel('asterisk_click2dial',netsvc.LOG_DEBUG,'International prefix = '+international_prefix+' - Number with international prefix = '+tmp_number)
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'International prefix = %s - Number with international prefix = %s'%(international_prefix,tmp_number))
# National format, allowed
# National format, allowed
elifast_server.national_format_allowed:
elifast_server.national_format_allowed:
@ -189,9 +166,21 @@ class asterisk_server(osv.osv):
# Add 'out prefix' to all numbers
# Add 'out prefix' to all numbers
tmp_number=out_prefix+tmp_number
tmp_number=out_prefix+tmp_number
logger.notifyChannel('asterisk_click2dial',netsvc.LOG_DEBUG,'Out prefix = '+out_prefix+' - Number to be sent to Asterisk = '+tmp_number)
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Out prefix = %s - Number to be sent to Asterisk = %s'%(out_prefix,tmp_number))
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Successfull logout from Asterisk : %s'%logout_answer)
else:
logger.notifyChannel('click2dial',netsvc.LOG_WARNING,'Logout from Asterisk failed : %s'%logout_answer)
# we catch only network problems here
exceptsocket.error:
logger.notifyChannel('click2dial',netsvc.LOG_WARNING,"Click2dial failed : unable to connect to Asterisk")
raiseosv.except_osv(_('Error :'),_("The connection from OpenERP to the Asterisk server failed. Please check the configuration on OpenERP and on Asterisk."))
raiseosv.except_osv(_('Error :'),_("The connection from OpenERP to the Asterisk server failed. Please check the configuration on OpenERP and on Asterisk."))
finally:
finally:
sock.close()
sock.close()
logger.notifyChannel('asterisk_click2dial',netsvc.LOG_INFO,"Asterisk Click2Dial from "+user.internal_number+' to '+ast_number)
logger.notifyChannel('click2dial',netsvc.LOG_INFO,"Asterisk Click2Dial from %s/%s to %s"%(user.asterisk_chan_type,user.internal_number,ast_number))
'callerid':fields.char('Caller ID',size=50,help="Caller ID used for the calls initiated by this user."),
'asterisk_chan_type':fields.selection([('SIP','SIP'),('IAX2','IAX2'),('DAHDI','DAHDI'),('Zap','Zap'),('Skinny','Skinny'),('MGCP','MGCP'),('mISDN','mISDN'),('H323','H323')],'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'."),
'asterisk_server_id':fields.many2one('asterisk.server','Asterisk server',help="Asterisk server on which the user's phone is connected."),
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."),