diff --git a/asterisk_click2dial/__openerp__.py b/asterisk_click2dial/__openerp__.py index 3c14565..46d799c 100644 --- a/asterisk_click2dial/__openerp__.py +++ b/asterisk_click2dial/__openerp__.py @@ -27,15 +27,15 @@ 'license': 'AGPL-3', 'description': """This module adds 3 functionnalities : -1) It adds a 'dial' button in the partner address form view so that users can directly dial a phone number through Asterisk. This feature is usually known as 'click2dial'. Here is how it works : -. In OpenERP, the user clicks on the 'dial' button next to a phone number field in the partner address view. +1) It adds a 'dial' button in the partner form view so that users can directly dial a phone number through Asterisk. This feature is usually known as 'click2dial'. Here is how it works : +. In OpenERP, the user clicks on the 'dial' button next to a phone number field in the partner view. . OpenERP connects to the Asterisk Manager Interface and Asterisk makes the user's phone ring. . The user answers his own phone (if he doesn't, the process stops here). . Asterisk dials the phone number found in OpenERP in place of the user. . If the remote party answers, the user can talk to his correspondent. 2) It adds the ability to show the name of the calling party on the screen of your IP phone on incoming phone calls if the presented -phone number is present in the partner addresses of OpenERP. Here is how it works : +phone number is present in the partners of OpenERP. Here is how it works : . On incoming phone calls, the Asterisk dialplan executes an AGI script "get_cid_name_timeout.sh". . The "get_cid_name_timeout.sh" script calls the "get_cid_name.py" script with a short timeout. . The "get_cid_name.py" script will make an XML-RPC request on the OpenERP server to try to find the name of the person corresponding to the phone number presented by the calling party. @@ -44,7 +44,7 @@ phone number is present in the partner addresses of OpenERP. Here is how it work 3) It adds a button "Open calling partner" in the menu "Sales > Address book" to get the partner corresponding to the calling party in one click. Here is how it works : . When the user clicks on the "Open calling partner" button, OpenERP sends a query to the Asterisk Manager Interface to get a list of the current phone calls . If it finds a phone call involving the user's phone, it gets the phone number of the calling party -. It searches the phone number of the calling party in the Partner addresses of OpenERP. If a record matches, it shows the name of the related Partner and proposes to open it, or open its related sale orders or invoices. If no record matches, it proposes to create a new Contact with the presented phone number as 'Phone' or 'Mobile' number or update an existing Contact. +. It searches the phone number of the calling party in the Partners of OpenERP. If a record matches, it shows the name of the related Partner and proposes to open it, or open its related sale orders or invoices. If no record matches, it proposes to create a new Contact with the presented phone number as 'Phone' or 'Mobile' number or update an existing Contact. A detailed documentation for this module is available on the Akretion Web site : http://www.akretion.com/en/products-and-services/openerp-asterisk-voip-connector """, 'author': 'Akretion', diff --git a/asterisk_click2dial/asterisk_click2dial.py b/asterisk_click2dial/asterisk_click2dial.py index 292446c..f5ebbbf 100644 --- a/asterisk_click2dial/asterisk_click2dial.py +++ b/asterisk_click2dial/asterisk_click2dial.py @@ -299,8 +299,6 @@ class asterisk_server(osv.osv): return calling_party_number -asterisk_server() - # Parameters specific for each user class res_users(osv.osv): @@ -354,44 +352,43 @@ class res_users(osv.osv): (_check_validity, "Error message in raise", ['resource', 'internal_number', 'callerid']), ] -res_users() -class res_partner_address(osv.osv): - _inherit = "res.partner.address" +class res_partner(osv.osv): + _inherit = "res.partner" def _format_phonenumber_to_e164(self, cr, uid, ids, name, arg, context=None): result = {} - for addr in self.read(cr, uid, ids, ['phone', 'mobile', 'fax'], context=context): - result[addr['id']] = {} + for partner in self.read(cr, uid, ids, ['phone', 'mobile', 'fax'], context=context): + result[partner['id']] = {} for fromfield, tofield in [('phone', 'phone_e164'), ('mobile', 'mobile_e164'), ('fax', 'fax_e164')]: - if not addr.get(fromfield): + if not partner.get(fromfield): res = False else: try: - res = phonenumbers.format_number(phonenumbers.parse(addr.get(fromfield), None), phonenumbers.PhoneNumberFormat.E164) + res = phonenumbers.format_number(phonenumbers.parse(partner.get(fromfield), None), phonenumbers.PhoneNumberFormat.E164) except Exception, e: - _logger.error("Cannot reformat the phone number '%s' to E.164 format. Error message: %s" % (addr.get(fromfield), e)) + _logger.error("Cannot reformat the phone number '%s' to E.164 format. Error message: %s" % (partner.get(fromfield), e)) _logger.error("You should fix this number and run the wizard 'Reformat all phone numbers' from the menu Settings > Configuration > Asterisk") # If I raise an exception here, it won't be possible to install # the module on a DB with bad phone numbers - #raise osv.except_osv(_('Error :'), _("Cannot reformat the phone number '%s' to E.164 format. Error message: %s" % (addr.get(fromfield), e))) + #raise osv.except_osv(_('Error :'), _("Cannot reformat the phone number '%s' to E.164 format. Error message: %s" % (partner.get(fromfield), e))) res = False - result[addr['id']][tofield] = res + result[partner['id']][tofield] = res #print "RESULT _format_phonenumber_to_e164", result return result _columns = { 'phone_e164': fields.function(_format_phonenumber_to_e164, type='char', size=64, string='Phone in E.164 format', readonly=True, multi="e164", store={ - 'res.partner.address': (lambda self, cr, uid, ids, c={}: ids, ['phone'], 10), + 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['phone'], 10), }), 'mobile_e164': fields.function(_format_phonenumber_to_e164, type='char', size=64, string='Mobile in E.164 format', readonly=True, multi="e164", store={ - 'res.partner.address': (lambda self, cr, uid, ids, c={}: ids, ['mobile'], 10), + 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['mobile'], 10), }), 'fax_e164': fields.function(_format_phonenumber_to_e164, type='char', size=64, string='Fax in E.164 format', readonly=True, multi="e164", store={ - 'res.partner.address': (lambda self, cr, uid, ids, c={}: ids, ['fax'], 10), + 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['fax'], 10), }), } @@ -421,12 +418,12 @@ class res_partner_address(osv.osv): def create(self, cr, uid, vals, context=None): vals_reformated = self._reformat_phonenumbers(cr, uid, vals, context=context) - return super(res_partner_address, self).create(cr, uid, vals_reformated, context=context) + return super(res_partner, self).create(cr, uid, vals_reformated, context=context) def write(self, cr, uid, ids, vals, context=None): vals_reformated = self._reformat_phonenumbers(cr, uid, vals, context=context) - return super(res_partner_address, self).write(cr, uid, ids, vals_reformated, context=context) + return super(res_partner, self).write(cr, uid, ids, vals_reformated, context=context) def dial(self, cr, uid, ids, phone_field=['phone', 'phone_e164'], context=None): @@ -444,13 +441,13 @@ class res_partner_address(osv.osv): def action_dial_phone(self, cr, uid, ids, context=None): '''Function called by the button 'Dial' next to the 'phone' field - in the partner address view''' + in the partner view''' return self.dial(cr, uid, ids, phone_field=['phone', 'phone_e164'], context=context) def action_dial_mobile(self, cr, uid, ids, context=None): '''Function called by the button 'Dial' next to the 'mobile' field - in the partner address view''' + in the partner view''' return self.dial(cr, uid, ids, phone_field=['mobile', 'mobile_e164'], context=context) @@ -484,17 +481,15 @@ class res_partner_address(osv.osv): res_ids = self.search(cr, uid, ['|', ('phone_e164', 'ilike', pg_seach_number), ('mobile_e164', 'ilike', pg_seach_number)], context=context) # TODO : use is_number_match() of the phonenumber lib ? if len(res_ids) > 1: - _logger.warning(u"There are several partners addresses (IDS = %s) with the same phone number %s" % (str(res_ids), number)) + _logger.warning(u"There are several partners (IDS = %s) with the same phone number %s" % (str(res_ids), number)) if res_ids: - entry = self.read(cr, uid, res_ids[0], ['name', 'partner_id'], context=context) + entry = self.read(cr, uid, res_ids[0], ['name', 'parent_id'], context=context) _logger.debug(u"Answer get_partner_from_phone_number with name = %s" % entry['name']) - return (entry['id'], entry['partner_id'] and entry['partner_id'][0] or False, entry['name']) + return (entry['id'], entry['parent_id'] and entry['parent_id'][0] or False, entry['name']) else: _logger.debug(u"No match for phone number %s" % number) return False -res_partner_address() - # This module supports multi-company class res_company(osv.osv): @@ -504,4 +499,3 @@ class res_company(osv.osv): 'asterisk_server_ids': fields.one2many('asterisk.server', 'company_id', 'Asterisk servers', help="List of Asterisk servers.") } -res_company() diff --git a/asterisk_click2dial/asterisk_click2dial_demo.xml b/asterisk_click2dial/asterisk_click2dial_demo.xml index f253b44..0d1450b 100644 --- a/asterisk_click2dial/asterisk_click2dial_demo.xml +++ b/asterisk_click2dial/asterisk_click2dial_demo.xml @@ -21,11 +21,13 @@ 11 + 11 Administrator <0141981242> 12 + 12 Demo user <0141984212> diff --git a/asterisk_click2dial/asterisk_server_view.xml b/asterisk_click2dial/asterisk_server_view.xml index 23511fb..ea14bd2 100644 --- a/asterisk_click2dial/asterisk_server_view.xml +++ b/asterisk_click2dial/asterisk_server_view.xml @@ -74,8 +74,8 @@ {'asterisk_server_main_view': True} - - + + diff --git a/asterisk_click2dial/res_partner_view.xml b/asterisk_click2dial/res_partner_view.xml index 3a94d96..b0a90bb 100644 --- a/asterisk_click2dial/res_partner_view.xml +++ b/asterisk_click2dial/res_partner_view.xml @@ -4,79 +4,64 @@ Copyright (C) 2010-2012 Alexis de Lattre The licence is in the file __openerp__.py - Inherit partner_address views to add 'Dial' button next to 'phone' + Inherit partner views to add 'Dial' button next to 'phone' and 'mobile' fields --> - - asterisk.res.partner.address.dial1 - res.partner.address + + asterisk.res.partner.simplified.form.dial + res.partner 15 - + - -