示例#1
0
    def _reformat_number(self,
                         cr,
                         uid,
                         erp_number,
                         ast_server=None,
                         context=None):
        '''
        This function is dedicated to the transformation of the number
        available in OpenERP to the number that Asterisk should dial.
        You may have to inherit this function in another module specific
        for your company if you are not happy with the way I reformat
        the OpenERP numbers.
        '''
        assert (erp_number), 'Missing phone number'
        _logger.debug('Number before reformat = %s' % erp_number)
        if not ast_server:
            ast_server = self._get_asterisk_server_from_user(cr,
                                                             uid,
                                                             context=context)

        # erp_number are supposed to be in E.164 format, so no need to
        # give a country code here
        parsed_num = phonenumbers.parse(erp_number, None)
        country_code = ast_server.company_id.country_id.code
        assert (country_code), 'Missing country on company'
        _logger.debug('Country code = %s' % country_code)
        to_dial_number = phonenumbers.format_out_of_country_calling_number(
            parsed_num, country_code.upper()).replace(' ',
                                                      '').replace('-', '')
        # Add 'out prefix' to all numbers
        if ast_server.out_prefix:
            _logger.debug('Out prefix = %s' % ast_server.out_prefix)
            to_dial_number = '%s%s' % (ast_server.out_prefix, to_dial_number)
        _logger.debug('Number to be sent to Asterisk = %s' % to_dial_number)
        return to_dial_number
    def _reformat_number(
            self, cr, uid, erp_number, fs_server=None, context=None):
        '''
        This function is dedicated to the transformation of the number
        available in OpenERP to the number that FreeSWITCH should dial.
        You may have to inherit this function in another module specific
        for your company if you are not happy with the way I reformat
        the OpenERP numbers.
        '''
        assert(erp_number), 'Missing phone number'
        _logger.debug('Number before reformat = %s' % erp_number)
        if not fs_server:
            fs_server = self._get_freeswitch_server_from_user(
                cr, uid, context=context)

        # erp_number are supposed to be in E.164 format, so no need to
        # give a country code here
        parsed_num = phonenumbers.parse(erp_number, None)
        country_code = fs_server.company_id.country_id.code
        assert(country_code), 'Missing country on company'
        _logger.debug('Country code = %s' % country_code)
        to_dial_number = phonenumbers.format_out_of_country_calling_number(
            parsed_num, country_code.upper()).replace(' ', '').replace('-', '').replace('(', '').replace(')', '')
        # Add 'out prefix' to all numbers
        if fs_server.out_prefix:
            _logger.debug('Out prefix = %s' % fs_server.out_prefix)
            to_dial_number = '%s%s' % (fs_server.out_prefix, to_dial_number)
        _logger.debug('Number to be sent to FreeSWITCH = %s' % to_dial_number)
        return to_dial_number
示例#3
0
 def _format_number(self, number, country_code=None, format_type='e164'):
     logger.debug('FORMAT_NUMBER %s COUNTRY %s FORMAT %s', number,
                  country_code, format_type)
     # Strip formatting if present
     number = number.replace(' ', '')
     number = number.replace('(', '')
     number = number.replace(')', '')
     number = number.replace('-', '')
     if len(self) == 1 and not country_code:
         # Called from partner object
         country_code = self._get_country_code()
         logger.debug('GOT COUNTRY FOR PARTNER %s CODE %s', self,
                      country_code)
     elif not country_code:
         # Get country code for requesting account
         country_code = self.env.user.partner_id._get_country_code()
         logger.debug('GOT COUNTRY CODE %s FROM ENV USER', country_code)
     elif not country_code:
         logger.debug('COULD NOT GET COUNTRY CODE')
     if country_code is False:
         # False -> None
         country_code = None
     try:
         phone_nbr = phonenumbers.parse(number, country_code)
         if not phonenumbers.is_possible_number(phone_nbr):
             logger.debug('PHONE NUMBER {} NOT POSSIBLE'.format(number))
         elif not phonenumbers.is_valid_number(phone_nbr):
             logger.debug('PHONE NUMBER {} NOT VALID'.format(number))
         # We have a parsed number, let check what format to return.
         elif format_type == 'out_of_country':
             # For out of country format we must get the Asterisk
             # agent country to format numbers according to it.
             country_code = self.env.user.partner_id._get_country_code()
             number = phonenumbers.format_out_of_country_calling_number(
                 phone_nbr, country_code)
             logger.debug('OUT OF COUNTRY FORMATTED NUMBER: %s', number)
         elif format_type == 'e164':
             number = phonenumbers.format_number(
                 phone_nbr, phonenumbers.PhoneNumberFormat.E164)
             logger.debug('E164 FORMATTED NUMBER: {}'.format(number))
         elif format_type == 'international':
             number = phonenumbers.format_number(
                 phone_nbr, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
             logger.debug('INTERN FORMATTED NUMBER: {}'.format(number))
         else:
             logger.error('WRONG FORMATTING PASSED: %s', format_type)
     except phonenumberutil.NumberParseException:
         logger.debug('PHONE NUMBER {} PARSE ERROR'.format(number))
     except Exception:
         logger.exception('FORMAT NUMBER ERROR:')
     finally:
         return number
示例#4
0
 def convert_to_dial_number(self, erp_number):
     '''
     This function is dedicated to the transformation of the number
     available in Odoo to the number that can be dialed.
     You may have to inherit this function in another module specific
     for your company if you are not happy with the way I reformat
     the numbers.
     '''
     assert(erp_number), 'Missing phone number'
     _logger.debug('Number before reformat = %s' % erp_number)
     # erp_number are supposed to be in E.164 format, so no need to
     # give a country code here
     parsed_num = phonenumbers.parse(erp_number, None)
     country_code = self.env.user.company_id.country_id.code
     assert(country_code), 'Missing country on company'
     _logger.debug('Country code = %s' % country_code)
     to_dial_number = phonenumbers.format_out_of_country_calling_number(
         parsed_num, country_code.upper())
     to_dial_number = str(to_dial_number).translate(None, ' -.()/')
     _logger.debug('Number to be sent to phone system: %s' % to_dial_number)
     return to_dial_number
 def convert_to_dial_number(self, erp_number):
     '''
     This function is dedicated to the transformation of the number
     available in Odoo to the number that can be dialed.
     You may have to inherit this function in another module specific
     for your company if you are not happy with the way I reformat
     the numbers.
     '''
     assert (erp_number), 'Missing phone number'
     _logger.debug('Number before reformat = %s' % erp_number)
     # erp_number are supposed to be in International format, so no need to
     # give a country code here
     parsed_num = phonenumbers.parse(erp_number, None)
     country_code = self.env.user.company_id.country_id.code
     assert (country_code), 'Missing country on company'
     _logger.debug('Country code = %s' % country_code)
     to_dial_number = phonenumbers.format_out_of_country_calling_number(
         parsed_num, country_code.upper())
     to_dial_number = str(to_dial_number).translate(None, ' -.()/')
     _logger.debug('Number to be sent to phone system: %s' % to_dial_number)
     return to_dial_number
示例#6
0
 def convert_to_dial_number(self, erp_number):
     """
     This function is dedicated to the transformation of the number
     available in Odoo to the number that can be dialed.
     You may have to inherit this function in another module specific
     for your company if you are not happy with the way I reformat
     the numbers.
     """
     assert erp_number, "Missing phone number"
     _logger.debug("Number before reformat = %s" % erp_number)
     # erp_number are supposed to be in International format, so no need to
     # give a country code here
     parsed_num = phonenumbers.parse(erp_number, None)
     country_code = self.env.company.country_id.code
     assert country_code, "Missing country on company"
     _logger.debug("Country code = %s" % country_code)
     to_dial_number = phonenumbers.format_out_of_country_calling_number(
         parsed_num, country_code.upper()
     )
     to_dial_number = to_dial_number.translate(
         to_dial_number.maketrans("", "", " -.()/")
     )
     _logger.debug("Number to be sent to phone system: %s" % to_dial_number)
     return to_dial_number