def _validate_address(self, cr, uid, address, avatax_config=False, context=None): """ Returns the valid address from the AvaTax Address Validation Service. """ avatax_config_obj= self.pool.get('avalara.salestax') if context is None: context = {} if not avatax_config: avatax_config = avatax_config_obj._get_avatax_config_company(cr, uid, context=context) if not avatax_config: raise osv.except_osv("AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation.") # Create the AvaTax Address service with the configuration parameters set for the instance if (not avatax_config.account_number or not avatax_config.license_key or not avatax_config.service_url or not avatax_config.request_timeout): raise osv.except_osv("AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation.") avapoint = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) addSvc = avapoint.create_address_service().addressSvc # Obtain the state code & country code and create a BaseAddress Object state_code = address.get('state_id') and self.get_state_code(cr, uid, address['state_id'], context=context) country_code = address.get('country_id') and self.get_country_code(cr, uid, address['country_id'], context=context) baseaddress = BaseAddress(addSvc, address.get('street') or None, address.get('street2') or None, address.get('city'), address.get('zip'), state_code, country_code, 0).data result = avapoint.validate_address(baseaddress, avatax_config.result_in_uppercase and 'Upper' or 'Default') valid_address = result.ValidAddresses[0][0] return valid_address
def _validate_address(self, cr, uid, address, avatax_config=False, context=None): """ Returns the valid address from the AvaTax Address Validation Service. """ avatax_config_obj = self.pool.get('avalara.salestax') if context is None: context = {} if not avatax_config: avatax_config = avatax_config_obj._get_avatax_config_company( cr, uid, context=context) if not avatax_config: raise osv.except_osv( "AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation." ) # Create the AvaTax Address service with the configuration parameters set for the instance if (not avatax_config.account_number or not avatax_config.license_key or not avatax_config.service_url or not avatax_config.request_timeout): raise osv.except_osv( "AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation." ) avapoint = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) addSvc = avapoint.create_address_service().addressSvc # Obtain the state code & country code and create a BaseAddress Object state_code = address.get('state_id') and self.get_state_code( cr, uid, address['state_id'], context=context) country_code = address.get('country_id') and self.get_country_code( cr, uid, address['country_id'], context=context) baseaddress = BaseAddress(addSvc, address.get('street') or None, address.get('street2') or None, address.get('city'), address.get('zip'), state_code, country_code, 0).data result = avapoint.validate_address( baseaddress, avatax_config.result_in_uppercase and 'Upper' or 'Default') valid_address = result.ValidAddresses[0][0] return valid_address