|
@ -29,6 +29,7 @@ from tools.translate import _ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class asterisk_server(osv.osv): |
|
|
class asterisk_server(osv.osv): |
|
|
|
|
|
'''Asterisk server object, to store all the parameters of the Asterisk IPBXs''' |
|
|
_name = "asterisk.server" |
|
|
_name = "asterisk.server" |
|
|
_description = "Asterisk Servers" |
|
|
_description = "Asterisk Servers" |
|
|
_columns = { |
|
|
_columns = { |
|
@ -63,7 +64,7 @@ class asterisk_server(osv.osv): |
|
|
def _only_digits(self, cr, uid, ids, prefix, can_be_empty): |
|
|
def _only_digits(self, cr, uid, ids, prefix, can_be_empty): |
|
|
for i in ids: |
|
|
for i in ids: |
|
|
prefix_to_check = self.read(cr, uid, i, [prefix])[prefix] |
|
|
prefix_to_check = self.read(cr, uid, i, [prefix])[prefix] |
|
|
if prefix_to_check == False: |
|
|
|
|
|
|
|
|
if not prefix_to_check: |
|
|
if can_be_empty: |
|
|
if can_be_empty: |
|
|
return True |
|
|
return True |
|
|
else: |
|
|
else: |
|
@ -189,7 +190,7 @@ class asterisk_server(osv.osv): |
|
|
logger.notifyChannel('asterisk_click2dial', netsvc.LOG_DEBUG, 'Out prefix = ' + out_prefix + ' - Number to be sent to Asterisk = ' + tmp_number) |
|
|
logger.notifyChannel('asterisk_click2dial', netsvc.LOG_DEBUG, 'Out prefix = ' + out_prefix + ' - Number to be sent to Asterisk = ' + tmp_number) |
|
|
return tmp_number |
|
|
return tmp_number |
|
|
|
|
|
|
|
|
def dial(self, cr, uid, ids, erp_number, context): |
|
|
|
|
|
|
|
|
def dial(self, cr, uid, ids, erp_number, context=None): |
|
|
''' |
|
|
''' |
|
|
Open the socket to the Asterisk Manager Interface (AMI) |
|
|
Open the socket to the Asterisk Manager Interface (AMI) |
|
|
and send instructions to Dial to Asterisk. That's the important function ! |
|
|
and send instructions to Dial to Asterisk. That's the important function ! |
|
@ -293,6 +294,30 @@ class res_partner_address(osv.osv): |
|
|
erp_number = self.read(cr, uid, ids, ['mobile'], context=context)[0]['mobile'] |
|
|
erp_number = self.read(cr, uid, ids, ['mobile'], context=context)[0]['mobile'] |
|
|
self.pool.get('asterisk.server').dial(cr, uid, ids, erp_number, context) |
|
|
self.pool.get('asterisk.server').dial(cr, uid, ids, erp_number, context) |
|
|
|
|
|
|
|
|
|
|
|
def get_name_from_phone_number(self, cr, uid, number, context=None): |
|
|
|
|
|
'''Function to get name from phone number. Usefull for use from Asterisk |
|
|
|
|
|
to add CallerID name to incoming calls |
|
|
|
|
|
To use this function from a python console/script : |
|
|
|
|
|
import xmlrpclib |
|
|
|
|
|
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object') |
|
|
|
|
|
sock.execute("openerp_database", user_id_num, "user_passwd", 'res.partner.address', 'get_name_from_phone_number', '141983212') |
|
|
|
|
|
''' |
|
|
|
|
|
res = {} |
|
|
|
|
|
logger = netsvc.Logger() |
|
|
|
|
|
netsvc.Logger().notifyChannel('asterisk_click2dial', netsvc.LOG_DEBUG, u"Call get_name_from_phone_number with number = " + number) |
|
|
|
|
|
res = self.search(cr, uid, [('phone', 'ilike', number)], context=context) |
|
|
|
|
|
if len(res) == 0: # if we find nothing, we continue with mobile |
|
|
|
|
|
res = self.search(cr, uid, [('mobile', 'ilike', number)], context=context) |
|
|
|
|
|
if len(res) == 1: # if we have a single match |
|
|
|
|
|
#print 'AST res =', res |
|
|
|
|
|
partner_address = self.read(cr, uid, res[0], ['name'], context=context)['name'] |
|
|
|
|
|
logger.notifyChannel('asterisk_click2dial', netsvc.LOG_DEBUG, u"Answer get_name_from_phone_number with name = %s" % partner_address) |
|
|
|
|
|
return partner_address |
|
|
|
|
|
# TODO what do we do when we have more than 1 match ? We take the first one ? |
|
|
|
|
|
# we don't do anything ? |
|
|
|
|
|
else: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
res_partner_address() |
|
|
res_partner_address() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|