# Lib required to open a socket (needed to communicate with Asterisk server)
importsocket
# Lib required to print logs
importnetsvc
importlogging
# Lib to translate error messages
fromtools.translateimport_
# Lib for regexp
importre
_logger=logging.getLogger(__name__)
classasterisk_server(osv.osv):
'''Asterisk server object, to store all the parameters of the Asterisk IPBXs'''
@ -106,7 +107,6 @@ class asterisk_server(osv.osv):
theOpenERPnumbers.
'''
logger=netsvc.Logger()
error_title_msg=_("Invalid phone number")
invalid_international_format_msg=_("The phone number is not written in valid international format. Example of valid international format : +33 1 41 98 12 42")
invalid_national_format_msg=_("The phone number is not written in valid national format.")
@ -114,7 +114,7 @@ class asterisk_server(osv.osv):
# Let's call the variable tmp_number now
tmp_number=erp_number
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Number before reformat = %s'%tmp_number)
_logger.debug('Number before reformat = %s'%tmp_number)
# Check if empty
ifnottmp_number:
@ -135,24 +135,24 @@ class asterisk_server(osv.osv):
iftmp_number[0]=='+':
# Remove the starting '+' of the number
tmp_number=tmp_number.replace('+','')
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Number after removal of special char = %s'%tmp_number)
_logger.debug('Number after removal of special char = %s'%tmp_number)
# At this stage, 'tmp_number' should only contain digits
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'National prefix = %s - Number with national prefix = %s'%(national_prefix,tmp_number))
_logger.debug('National prefix = %s - Number with national prefix = %s'%(national_prefix,tmp_number))
else:
# If the number is an international number,
# add 'international prefix'
tmp_number=international_prefix+tmp_number
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'International prefix = %s - Number with international prefix = %s'%(international_prefix,tmp_number))
_logger.debug('International prefix = %s - Number with international prefix = %s'%(international_prefix,tmp_number))
# National format, allowed
elifast_server.national_format_allowed:
@ -166,7 +166,7 @@ class asterisk_server(osv.osv):
# Add 'out prefix' to all numbers
tmp_number=out_prefix+tmp_number
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Out prefix = %s - Number to be sent to Asterisk = %s'%(out_prefix,tmp_number))
_logger.debug('Out prefix = %s - Number to be sent to Asterisk = %s'%(out_prefix,tmp_number))
returntmp_number
@ -187,7 +187,6 @@ class asterisk_server(osv.osv):
andsendinstructionstoDialtoAsterisk.That's the important function !
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,'Successfull logout from Asterisk : %s'%logout_answer)
_logger.debug('Successfull logout from Asterisk : %s'%logout_answer)
else:
logger.notifyChannel('click2dial',netsvc.LOG_WARNING,'Logout from Asterisk failed : %s'%logout_answer)
_logger.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")
_logger.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."))
finally:
sock.close()
logger.notifyChannel('click2dial',netsvc.LOG_INFO,"Asterisk Click2Dial from %s/%s to %s"%(user.asterisk_chan_type,user.internal_number,ast_number))
_logger.info("Asterisk Click2Dial from %s/%s to %s"%(user.asterisk_chan_type,user.internal_number,ast_number))
returnTrue
@ -359,14 +356,13 @@ class res_partner_address(osv.osv):
request.
'''
res={}
logger=netsvc.Logger()
# We check that "number" is really a number
ifnotisinstance(number,str):
returnFalse
ifnotnumber.isdigit():
returnFalse
netsvc.Logger().notifyChannel('click2dial',netsvc.LOG_DEBUG,u"Call get_name_from_phone_number with number = %s"%number)
_logger.debug(u"Call get_name_from_phone_number with number = %s"%number)
# Get all the partner addresses :
all_ids=self.search(cr,uid,[],context=context)
# For each partner address, we check if the number matches on the "phone" or "mobile" fields
@ -374,14 +370,14 @@ class res_partner_address(osv.osv):
ifentry.phone:
# We use a regexp on the phone field to remove non-digit caracters
ifre.sub(r'\D','',entry.phone).endswith(number):
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,u"Answer get_name_from_phone_number with name = %s"%entry.name)
_logger.debug(u"Answer get_name_from_phone_number with name = %s"%entry.name)
returnentry.name
ifentry.mobile:
ifre.sub(r'\D','',entry.mobile).endswith(number):
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,u"Answer get_name_from_phone_number with name = %s"%entry.name)
_logger.debug(u"Answer get_name_from_phone_number with name = %s"%entry.name)
returnentry.name
logger.notifyChannel('click2dial',netsvc.LOG_DEBUG,u"No match for phone number %s"%number)
_logger.debug(u"No match for phone number %s"%number)