Browse Source

First implementation of get_name_from_phone_number function

Make phone and mobile fields searchable
Took into account some pylint coding convention suggestions
6.0
Alexis de Lattre 14 years ago
parent
commit
8957a378bf
  1. 2
      asterisk_click2dial/__terp__.py
  2. 29
      asterisk_click2dial/asterisk_click2dial.py
  3. 12
      asterisk_click2dial/res_partner_view.xml

2
asterisk_click2dial/__terp__.py

@ -22,7 +22,7 @@
{
'name': 'Asterisk Click2dial',
'version': '0.1',
'version': '0.2',
'category': 'Generic Modules/Others',
'license': 'AGPL-3',
'description': """This module adds a 'dial' button in the partner address

29
asterisk_click2dial/asterisk_click2dial.py

@ -29,6 +29,7 @@ from tools.translate import _
class asterisk_server(osv.osv):
'''Asterisk server object, to store all the parameters of the Asterisk IPBXs'''
_name = "asterisk.server"
_description = "Asterisk Servers"
_columns = {
@ -63,7 +64,7 @@ class asterisk_server(osv.osv):
def _only_digits(self, cr, uid, ids, prefix, can_be_empty):
for i in ids:
prefix_to_check = self.read(cr, uid, i, [prefix])[prefix]
if prefix_to_check == False:
if not prefix_to_check:
if can_be_empty:
return True
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)
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)
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']
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()

12
asterisk_click2dial/res_partner_view.xml

@ -21,14 +21,14 @@
<field name="phone" position="replace">
<label string="Phone : " align="1.0" />
<group colspan="1" col="5">
<field name="phone" nolabel="1" colspan="4" />
<field name="phone" nolabel="1" colspan="4" select="2" />
<button name="action_dial_phone" string="Dial" type="object"/>
</group>
</field>
<field name="mobile" position="replace">
<label string="Mobile : " align="1.0" />
<group colspan="1" col="5">
<field name="mobile" nolabel="1" colspan="4" />
<field name="mobile" nolabel="1" colspan="4" select="2" />
<button name="action_dial_mobile" string="Dial" type="object"/>
</group>
</field>
@ -46,14 +46,14 @@
<field name="phone" position="replace">
<label string="Phone : " align="1.0" />
<group colspan="1" col="5">
<field name="phone" nolabel="1" colspan="4" />
<field name="phone" nolabel="1" colspan="4" select="2" />
<button name="action_dial_phone" string="Dial" type="object"/>
</group>
</field>
<field name="mobile" position="replace">
<label string="Mobile : " align="1.0" />
<group colspan="1" col="5">
<field name="mobile" nolabel="1" colspan="4" />
<field name="mobile" nolabel="1" colspan="4" select="2" />
<button name="action_dial_mobile" string="Dial" type="object"/>
</group>
</field>
@ -71,14 +71,14 @@
<field name="phone" position="replace">
<label string="Phone : " align="1.0" />
<group colspan="1" col="5">
<field name="phone" nolabel="1" colspan="4" />
<field name="phone" nolabel="1" colspan="4" select="2" />
<button name="action_dial_phone" string="Dial" type="object"/>
</group>
</field>
<field name="mobile" position="replace">
<label string="Mobile : " align="1.0" />
<group colspan="1" col="5">
<field name="mobile" nolabel="1" colspan="4" />
<field name="mobile" nolabel="1" colspan="4" select="2" />
<button name="action_dial_mobile" string="Dial" type="object"/>
</group>
</field>

Loading…
Cancel
Save