Browse Source

Add a "Test Connection to Asterisk" button on the asterisk.server form view.

pull/7/head
Alexis de Lattre 10 years ago
parent
commit
fbb54eefd1
  1. 30
      asterisk_click2dial/asterisk_click2dial.py
  2. 10
      asterisk_click2dial/asterisk_server_view.xml

30
asterisk_click2dial/asterisk_click2dial.py

@ -200,7 +200,6 @@ class asterisk_server(orm.Model):
ast_server = self.browse(cr, uid, asterisk_server_ids[0], context=context)
return ast_server
def _connect_to_asterisk(self, cr, uid, context=None):
'''
Open the connection to the Asterisk Manager
@ -229,13 +228,36 @@ class asterisk_server(orm.Model):
try:
ast_manager = Manager.Manager((ast_server.ip_address, ast_server.port), ast_server.login, ast_server.password)
except Exception, e:
_logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address)
_logger.error("Here is the detail of the error : %s" % e.strerror)
raise orm.except_orm(_('Error :'), _("Problem in the request from OpenERP to Asterisk. Here is the detail of the error: %s." % e.strerror))
_logger.error("Error in the request to the Asterisk Manager Interface %s" % ast_server.ip_address)
_logger.error("Here is the error message: %s" % e)
raise orm.except_orm(_('Error :'), _("Problem in the request from OpenERP to Asterisk. Here is the error message: %s" % e))
return False
return (user, ast_server, ast_manager)
def test_ami_connection(self, cr, uid, ids, context=None):
assert len(ids) == 1, 'Only 1 ID'
ast_server = self.browse(cr, uid, ids[0], context=context)
try:
ast_manager = Manager.Manager(
(ast_server.ip_address, ast_server.port),
ast_server.login,
ast_server.password)
except Exception, e:
raise orm.except_orm(
_("Connection Test Failed!"),
_("Here is the error message: %s" % e))
finally:
try:
if ast_manager:
ast_manager.Logoff()
except Exception:
pass
raise orm.except_orm(
_("Connection Test Successfull!"),
_("OpenERP can successfully login to the Asterisk Manager "
"Interface."))
def _dial_with_asterisk(self, cr, uid, erp_number, context=None):
#print "_dial_with_asterisk erp_number=", erp_number
if not erp_number:

10
asterisk_click2dial/asterisk_server_view.xml

@ -35,13 +35,19 @@
</div>
<group name="main">
<field name="company_id"
invisible="not context.get('asterisk_server_main_view')"
groups="base.group_multi_company"/>
<field name="active" />
</group>
<group name="ami" string="Asterisk Manager Interface">
<field name="ip_address" />
<field name="port" />
<field name="login" />
<field name="password" password="True" />
<button name="test_ami_connection" type="object"
string="Test Connection to Asterisk"
icon="gtk-network" colspan="2"/>
</group>
<group name="dialplan" string="Dialplan Parameters">
<field name="context" />
<field name="extension_priority" />
<field name="out_prefix" />
@ -65,7 +71,6 @@
<field name="name" />
<field name="ip_address" />
<field name="company_id"
invisible="not context.get('asterisk_server_main_view')"
groups="base.group_multi_company" />
<field name="country_prefix" />
</tree>
@ -77,7 +82,6 @@
<field name="name">Asterisk Servers</field>
<field name="res_model">asterisk.server</field>
<field name="view_mode">tree,form</field>
<field name="context">{'asterisk_server_main_view': True}</field>
</record>
<!-- Menu entry under Settings > Technical > Phone -->

Loading…
Cancel
Save