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. 75
      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

75
asterisk_click2dial/asterisk_click2dial.py

@ -29,25 +29,26 @@ 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 = {
'name' : fields.char('Asterisk server name', size=50, required=True, help="Asterisk server name."),
'active' : fields.boolean('Active', help="The active field allows you to hide the Asterisk server without deleting it."),
'ip_address' : fields.char('Asterisk IP addr. or DNS', size=50, required=True, help="IPv4 address or DNS name of the Asterisk server."),
'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."),
'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'."),
'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 ?"),
'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."),
'password' : fields.char('AMI password', size=30, required=True, help="Password that Asterisk will use to communicate with the Asterisk Manager Interface. Refer to /etc/asterisk/manager.conf on your Asterisk server."),
'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=40, help="Set Alert-Info header in SIP request to user's IP Phone. If empty, the Alert-Info header will not be added. You can use it to have a special ring tone for click2dial, for example you could choose a silent ring tone."),
'company_id' : fields.many2one('res.company', 'Company', help="Company who uses the Asterisk server."),
'name': fields.char('Asterisk server name', size=50, required=True, help="Asterisk server name."),
'active': fields.boolean('Active', help="The active field allows you to hide the Asterisk server without deleting it."),
'ip_address': fields.char('Asterisk IP addr. or DNS', size=50, required=True, help="IPv4 address or DNS name of the Asterisk server."),
'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."),
'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'."),
'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 ?"),
'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."),
'password': fields.char('AMI password', size=30, required=True, help="Password that Asterisk will use to communicate with the Asterisk Manager Interface. Refer to /etc/asterisk/manager.conf on your Asterisk server."),
'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=40, help="Set Alert-Info header in SIP request to user's IP Phone. If empty, the Alert-Info header will not be added. You can use it to have a special ring tone for click2dial, for example you could choose a silent ring tone."),
'company_id': fields.many2one('res.company', 'Company', help="Company who uses the Asterisk server."),
}
_defaults = {
@ -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:
@ -152,7 +153,7 @@ class asterisk_server(osv.osv):
out_prefix = (ast_server.out_prefix or '')
# International format
if tmp_number[0]=='+':
if tmp_number[0] == '+':
# Remove the starting '+' of the number
tmp_number = tmp_number.replace('+','')
logger.notifyChannel('asterisk_click2dial', netsvc.LOG_DEBUG, 'Number after removal of special char = ' + tmp_number)
@ -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 !
@ -264,10 +265,10 @@ class res_users(osv.osv):
_name = "res.users"
_inherit = "res.users"
_columns = {
'internal_number' : fields.char('Internal number', size=15, help="User's internal phone 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."),
'internal_number': fields.char('Internal number', size=15, help="User's internal phone 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."),
}
_defaults = {
@ -279,7 +280,7 @@ res_users()
class res_partner_address(osv.osv):
_name = "res.partner.address"
_inherit ="res.partner.address"
_inherit = "res.partner.address"
def action_dial_phone(self, cr, uid, ids, context):
'''Function called by the button 'Dial' next to the 'phone' field
@ -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()
@ -301,7 +326,7 @@ class res_company(osv.osv):
_name = "res.company"
_inherit = "res.company"
_columns = {
'asterisk_server_ids' : fields.one2many('asterisk.server', 'company_id', 'Asterisk servers', help="List of Asterisk servers.")
'asterisk_server_ids': fields.one2many('asterisk.server', 'company_id', 'Asterisk servers', help="List of Asterisk servers.")
}
res_company()

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