From 8f3040d085a8f229166e5ca01a708b75bf32569d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 21 Aug 2014 00:41:52 +0200 Subject: [PATCH] The "Dial" button is now inside the phone widget : this is great because it avoids the double inherit of views with phone fields (4 view XML files are removed in asterisk_click2dial* modules thanks to this !) The "Open Calling Partner" feature is now located in the top right menu, next to the Preferences (instead of the Sales menu) A click on tel: and fax: links doesn't open a new tab any more Update description and copyrights of asterisk_click2dial_crm --- asterisk_click2dial/__openerp__.py | 4 +- asterisk_click2dial/asterisk_click2dial.py | 101 ++++++++---------- asterisk_click2dial/res_partner_view.xml | 70 ------------ .../static/src/css/asterisk_click2dial.css | 27 +++++ .../static/src/js/asterisk_click2dial.js | 44 ++++++++ .../static/src/xml/asterisk_click2dial.xml | 26 +++++ .../wizard/open_calling_partner_view.xml | 10 -- asterisk_click2dial_crm/__init__.py | 4 +- asterisk_click2dial_crm/__openerp__.py | 9 +- .../asterisk_click2dial_crm.py | 46 ++++---- asterisk_click2dial_crm/crm_lead_view.xml | 57 ---------- .../crm_phonecall_view.xml | 26 ----- .../wizard/create_crm_phonecall.py | 2 - .../wizard/open_calling_partner_view.xml | 9 -- asterisk_click2dial_crm_claim/__openerp__.py | 1 - .../crm_claim_view.xml | 29 ----- asterisk_click2dial_event/__openerp__.py | 2 - .../registration_view.xml | 47 -------- base_phone/__init__.py | 1 + base_phone/__openerp__.py | 2 +- base_phone/base_phone.py | 5 + base_phone/controller.py | 35 ++++++ base_phone/static/src/js/phone_widget.js | 63 ++++++++--- base_phone/static/src/xml/phone.xml | 13 ++- 24 files changed, 269 insertions(+), 364 deletions(-) delete mode 100644 asterisk_click2dial/res_partner_view.xml create mode 100644 asterisk_click2dial/static/src/css/asterisk_click2dial.css create mode 100644 asterisk_click2dial/static/src/js/asterisk_click2dial.js create mode 100644 asterisk_click2dial/static/src/xml/asterisk_click2dial.xml delete mode 100644 asterisk_click2dial_crm/crm_lead_view.xml delete mode 100644 asterisk_click2dial_crm/crm_phonecall_view.xml delete mode 100644 asterisk_click2dial_crm_claim/crm_claim_view.xml delete mode 100644 asterisk_click2dial_event/registration_view.xml create mode 100644 base_phone/controller.py diff --git a/asterisk_click2dial/__openerp__.py b/asterisk_click2dial/__openerp__.py index f75eb5c..9e88d11 100644 --- a/asterisk_click2dial/__openerp__.py +++ b/asterisk_click2dial/__openerp__.py @@ -57,7 +57,6 @@ A detailed documentation for this module is available on the Akretion Web site : 'data': [ 'asterisk_server_view.xml', 'res_users_view.xml', - 'res_partner_view.xml', 'wizard/open_calling_partner_view.xml', 'security/ir.model.access.csv', ], @@ -66,6 +65,9 @@ A detailed documentation for this module is available on the Akretion Web site : 'images/sshot-click2dial.jpg', 'images/sshot-open_calling_party.jpg', ], + 'qweb': ['static/src/xml/*.xml'], + 'js': ['static/src/js/*.js'], + 'css': ['static/src/css/*.css'], 'application': True, 'installable': True, 'active': False, diff --git a/asterisk_click2dial/asterisk_click2dial.py b/asterisk_click2dial/asterisk_click2dial.py index d81b89d..950a905 100644 --- a/asterisk_click2dial/asterisk_click2dial.py +++ b/asterisk_click2dial/asterisk_click2dial.py @@ -258,49 +258,6 @@ class asterisk_server(orm.Model): _("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: - raise orm.except_orm(_('Error :'), "Hara kiri : you must call the function with erp_number") - - user, ast_server, ast_manager = self._connect_to_asterisk(cr, uid, context=context) - ast_number = self._reformat_number(cr, uid, erp_number, ast_server, context=context) - - # The user should have a CallerID - if not user.callerid: - raise orm.except_orm(_('Error :'), _('No callerID configured for the current user')) - - variable = [] - if user.asterisk_chan_type == 'SIP': - # We can only have one alert-info header in a SIP request - if user.alert_info: - variable.append('SIPAddHeader=Alert-Info: ' + user.alert_info) - elif ast_server.alert_info: - variable.append('SIPAddHeader=Alert-Info: ' + ast_server.alert_info) - if user.variable: - for user_variable in user.variable.split('|'): - variable.append(user_variable.strip()) - - try: - ast_manager.Originate( - user.asterisk_chan_type + '/' + user.resource + ( ('/' + user.dial_suffix) if user.dial_suffix else ''), - context = ast_server.context, - extension = ast_number, - priority = str(ast_server.extension_priority), - timeout = str(ast_server.wait_time*1000), - caller_id = user.callerid, - account = user.cdraccount, - variable = variable) - 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'" % unicode(e)) - raise orm.except_orm(_('Error :'), _("Click to dial with Asterisk failed.\nHere is the error: '%s'" % unicode(e))) - - finally: - ast_manager.Logoff() - - return True - def _get_calling_number(self, cr, uid, context=None): user, ast_server, ast_manager = self._connect_to_asterisk(cr, uid, context=context) @@ -397,20 +354,50 @@ class res_users(orm.Model): class phone_common(orm.AbstractModel): _inherit = 'phone.common' - def action_dial(self, cr, uid, ids, context=None): - '''Read the number to dial and call _connect_to_asterisk the right way''' - if context is None: - context = {} - if not isinstance(context.get('field2dial'), (unicode, str)): - raise orm.except_orm(_('Error :'), "The function action_dial must be called with a 'field2dial' key in the context containing a string ''.") - else: - phone_field = context.get('field2dial') - erp_number_read = self.read(cr, uid, ids[0], [phone_field], context=context) - erp_number_e164 = erp_number_read[phone_field] - # Check if the number to dial is not empty - if not erp_number_e164: - raise orm.except_orm(_('Error :'), _('There is no phone number !')) - return self.pool['asterisk.server']._dial_with_asterisk(cr, uid, erp_number_e164, context=context) + def click2dial(self, cr, uid, erp_number, context=None): + if not erp_number: + orm.except_orm( + _('Error:'), + _('Missing phone number')) + + user, ast_server, ast_manager = self.pool['asterisk.server']._connect_to_asterisk(cr, uid, context=context) + ast_number = self.pool['asterisk.server']._reformat_number( + cr, uid, erp_number, ast_server, context=context) + + # The user should have a CallerID + if not user.callerid: + raise orm.except_orm(_('Error :'), _('No callerID configured for the current user')) + + variable = [] + if user.asterisk_chan_type == 'SIP': + # We can only have one alert-info header in a SIP request + if user.alert_info: + variable.append('SIPAddHeader=Alert-Info: ' + user.alert_info) + elif ast_server.alert_info: + variable.append('SIPAddHeader=Alert-Info: ' + ast_server.alert_info) + if user.variable: + for user_variable in user.variable.split('|'): + variable.append(user_variable.strip()) + + try: + ast_manager.Originate( + user.asterisk_chan_type + '/' + user.resource + ( ('/' + user.dial_suffix) if user.dial_suffix else ''), + context = ast_server.context, + extension = ast_number, + priority = str(ast_server.extension_priority), + timeout = str(ast_server.wait_time*1000), + caller_id = user.callerid, + account = user.cdraccount, + variable = variable) + 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'" % unicode(e)) + raise orm.except_orm(_('Error :'), _("Click to dial with Asterisk failed.\nHere is the error: '%s'" % unicode(e))) + + finally: + ast_manager.Logoff() + + return True def _prepare_incall_pop_action( self, cr, uid, record_res, number, context=None): diff --git a/asterisk_click2dial/res_partner_view.xml b/asterisk_click2dial/res_partner_view.xml deleted file mode 100644 index 4264da0..0000000 --- a/asterisk_click2dial/res_partner_view.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - asterisk.res.partner.simplified.form.dial - res.partner - 15 - - - - - -