コード例 #1
0
	def address_validation(self, credentials, add_doc, country_doc):
		from fedex.services.address_validation_service import FedexAddressValidationRequest
		avs_request = FedexAddressValidationRequest(credentials)
		if add_doc.state_rigpl is not None and add_doc.state_rigpl != "":
			state_doc = frappe.get_doc("State", add_doc.state_rigpl)
		else:
			state_doc = ""
		if state_doc != "":
			state_code = state_doc.state_code
		else:
			state_code = ""
		address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
		address1.Address.StreetLines = [str(add_doc.address_line1)[0:35], \
			str(add_doc.address_line2)[0:35]]
		address1.Address.City = str(add_doc.city)[0:20]
		address1.Address.StateOrProvinceCode = str(state_code)[0:2]
		address1.Address.PostalCode = str(add_doc.pincode)[0:10]
		address1.Address.CountryCode = str(country_doc.code)[0:2]
		address1.Address.CountryName = add_doc.country
		address1.Address.Residential = add_doc.is_residential
		avs_request.add_address(address1)
		avs_request.send_request()
		
		for i in range(len(avs_request.response.AddressResults)):
			frappe.msgprint("Details for Address {}".format(i + 1))
			frappe.msgprint("The validated street is: {}"
				"".format(avs_request.response.AddressResults[i].EffectiveAddress.StreetLines))
			frappe.msgprint("The validated city is: {}"
				"".format(avs_request.response.AddressResults[i].EffectiveAddress.City))
			frappe.msgprint("The validated state code is: {}"
				"".format(avs_request.response.AddressResults[i].EffectiveAddress.StateOrProvinceCode))
			frappe.msgprint("The validated postal code is: {}"
				"".format(avs_request.response.AddressResults[i].EffectiveAddress.PostalCode))
			frappe.msgprint("The validated country code is: {}"
				"".format(avs_request.response.AddressResults[i].EffectiveAddress.CountryCode))
コード例 #2
0
ファイル: fedex_account.py プロジェクト: gitlabuser/OdooUSA
    def address_validation(self, address_id):
        """ This function is called from the wizard.Performs the actual computing in address validation """
        status = 0
        error_msg = ''
        fedex_accounts = self.env['fedex.account'].search([])
        if not fedex_accounts:
            warning = {
                'title': "No FedEx account!",
                'message': "No FedEx account found for validation."
            }
            return {'warning': warning}
        if fedex_accounts and address_id:
            fedex_account = fedex_accounts[0]
            if type(address_id) == type([]):
                address_id = address_id[0]
            partner_address = self.env['res.partner'].browse(address_id)
            from fedex.config import FedexConfig

            config_obj = FedexConfig(
                key=fedex_account.fedex_key,
                password=fedex_account.fedex_password,
                account_number=fedex_account.fedex_account_number,
                meter_number=fedex_account.fedex_meter_number,
                use_test_server=fedex_account.test_mode)
            from fedex.services.address_validation_service import FedexAddressValidationRequest

            address = FedexAddressValidationRequest(config_obj)
            address1 = address.create_wsdl_object_of_type('AddressToValidate')
            address1.CompanyName = partner_address.name or ''
            address1.Address.StreetLines = [
                partner_address.street, partner_address.street2
            ]
            address1.Address.City = partner_address.city
            address1.Address.StateOrProvinceCode = partner_address.state_id and partner_address.state_id.code or ''
            address1.Address.PostalCode = partner_address.zip
            address1.Address.CountryCode = partner_address.country_id and partner_address.country_id.code or ''
            address1.Address.Residential = False

            address.add_address(address1)

            ret_list = []
            try:
                address.send_request()
                response = address.response
                #Possible values ERROR, FAILURE, NOTE, WARNING, SUCCESS
                if response.HighestSeverity == 'SUCCESS':
                    error_msg = "The address is valid"
                    status = 1
                elif response.HighestSeverity == 'ERROR' or response.HighestSeverity == 'FAILURE':
                    error_msg = str(response.Notifications[0].Message)
            except Exception, e:
                error_msg = error_msg + str(e)
            return {
                'addr_status': status,
                'error_msg': error_msg,
                'address_list': ret_list
            }
コード例 #3
0
    def address_validation(self, cr, uid, address_id, context={}):
        """ This function is called from the wizard.Performs the actual computing in address validation """
        status = 0
        error_msg = ''
        
        fedex_accounts = self.pool.get('fedex.account').search(cr, uid, [], context={})
        if not fedex_accounts:
            warning = {
                'title': "No FedEx account!",
                'message': "No FedEx account found for validation."
            }
            return {'warning': warning} 
        if fedex_accounts and address_id:
            fedex_account = self.pool.get('fedex.account').browse(cr, uid, fedex_accounts[0], context=context)
            if type(address_id) == type([]):
                address_id = address_id[0]
            partner_address = self.pool.get('res.partner').browse(cr, uid, address_id, context=context)
            from fedex.config import FedexConfig
            config_obj = FedexConfig(key=fedex_account.fedex_key,
                             password=fedex_account.fedex_password,
                             account_number=fedex_account.fedex_account_number,
                             meter_number=fedex_account.fedex_meter_number,
                             use_test_server=fedex_account.test_mode)
            from fedex.services.address_validation_service import FedexAddressValidationRequest
            
            address = FedexAddressValidationRequest(config_obj)

            address1 = address.create_wsdl_object_of_type('AddressToValidate')
            address1.CompanyName = partner_address.name or ''
            address1.Address.StreetLines = [ partner_address.street, partner_address.street2 ]
            address1.Address.City = partner_address.city
            address1.Address.StateOrProvinceCode = partner_address.state_id and partner_address.state_id.code or ''
            address1.Address.PostalCode = partner_address.zip
            address1.Address.CountryCode = partner_address.country_id and  partner_address.country_id.code or ''
            address1.Address.Residential = False
            
            address.add_address(address1)
            
            ret_list = []
            try:
                address.send_request()
                response = address.response
                #Possible values ERROR, FAILURE, NOTE, WARNING, SUCCESS
                if response.HighestSeverity == 'SUCCESS':
                    error_msg = "The address is valid"
                    status = 1
                elif response.HighestSeverity == 'ERROR' or response.HighestSeverity == 'FAILURE':
                    error_msg = str(response.Notifications[0].Message)
            except Exception, e:
                error_msg = error_msg + str(e)
            return {
                'addr_status':status,
                'error_msg':error_msg,
                'address_list':ret_list
            }
コード例 #4
0
    def test_avs(self):
        avs_request = FedexAddressValidationRequest(CONFIG_OBJ)

        address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
        address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
        address1.Address.City = 'Clemson'
        address1.Address.StateOrProvinceCode = 'SC'
        address1.Address.PostalCode = 29631
        address1.Address.CountryCode = 'US'
        address1.Address.Residential = False
        avs_request.add_address(address1)

        avs_request.send_request()

        assert avs_request.response
コード例 #5
0
    def test_avs(self):
        avs_request = FedexAddressValidationRequest(CONFIG_OBJ)

        address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
        address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
        address1.Address.City = 'Clemson'
        address1.Address.StateOrProvinceCode = 'SC'
        address1.Address.PostalCode = 29631
        address1.Address.CountryCode = 'US'
        address1.Address.Residential = False
        avs_request.add_address(address1)

        avs_request.send_request()

        assert avs_request.response
コード例 #6
0
    def address_validation(self, credentials, add_doc, country_doc):
        from fedex.services.address_validation_service import FedexAddressValidationRequest
        avs_request = FedexAddressValidationRequest(credentials)
        if add_doc.state_rigpl is not None and add_doc.state_rigpl != "":
            state_doc = frappe.get_doc("State", add_doc.state_rigpl)
        else:
            state_doc = ""
        if state_doc != "":
            state_code = state_doc.state_code
        else:
            state_code = ""
        address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
        address1.Address.StreetLines = [str(add_doc.address_line1)[0:35], \
         str(add_doc.address_line2)[0:35]]
        address1.Address.City = str(add_doc.city)[0:20]
        address1.Address.StateOrProvinceCode = str(state_code)[0:2]
        address1.Address.PostalCode = str(add_doc.pincode)[0:10]
        address1.Address.CountryCode = str(country_doc.code)[0:2]
        address1.Address.CountryName = add_doc.country
        address1.Address.Residential = add_doc.is_residential
        avs_request.add_address(address1)
        avs_request.send_request()

        for i in range(len(avs_request.response.AddressResults)):
            frappe.msgprint("Details for Address {}".format(i + 1))
            frappe.msgprint("The validated street is: {}"
                            "".format(avs_request.response.AddressResults[i].
                                      EffectiveAddress.StreetLines))
            frappe.msgprint("The validated city is: {}"
                            "".format(avs_request.response.AddressResults[i].
                                      EffectiveAddress.City))
            frappe.msgprint("The validated state code is: {}"
                            "".format(avs_request.response.AddressResults[i].
                                      EffectiveAddress.StateOrProvinceCode))
            frappe.msgprint("The validated postal code is: {}"
                            "".format(avs_request.response.AddressResults[i].
                                      EffectiveAddress.PostalCode))
            frappe.msgprint("The validated country code is: {}"
                            "".format(avs_request.response.AddressResults[i].
                                      EffectiveAddress.CountryCode))
コード例 #7
0
    def fedex_validate_address(self, picking, data):
        # NOTE: TO USE ADDRESS VALIDATION SERVICES, YOU NEED TO REQUEST FEDEX TO ENABLE THIS SERVICE FOR YOUR ACCOUNT.
        # BY DEFAULT, THE SERVICE IS DISABLED AND YOU WILL RECEIVE AUTHENTICATION FAILED, 1000 RESPONSE.
        client_language_code = 'EN'
        client_locale_code = 'US'
        CONFIG_OBJ = FedexConfig(key=self.fedex_developer_key,
                                 password=self.fedex_developer_password,
                                 account_number=self.fedex_account_number,
                                 meter_number=self.fedex_meter_number,
                                 use_test_server=True if self.fedex_environment
                                 == 'test' else False)
        customer_transaction_id = 'Address validation for %s' % picking.name
        avs_request = FedexAddressValidationRequest(
            CONFIG_OBJ,
            customer_transaction_id=customer_transaction_id,
            client_locale_code=client_locale_code,
            client_language_code=client_language_code)

        # Create some addresses to validate
        address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
        address1.ClientReferenceId = picking.partner_id
        address1.Address.StreetLines = picking.partner_id.street
        address1.Address.City = data['toCity']
        address1.Address.StateOrProvinceCode = data['toState']
        address1.Address.PostalCode = data['toPostalCode']
        address1.Address.CountryCode = data['toCountry']
        avs_request.add_address(address1)

        avs_request.send_request()

        if len(avs_request.response.AddressResults):
            is_resident = avs_request.response.AddressResults[
                0].Classification != 'BUSINESS'  # Non BUSINESS means residential address
            return is_resident
        else:
            return False  # by default consider it false
コード例 #8
0
ファイル: sale.py プロジェクト: BMA-Projects/Dard
    def fedex_address_validation(self, cr, uid, ids, context=None):
        partneraddr_obj = self.pool.get('res.partner')
        shippingfedex_obj = self.pool.get('shipping.fedex')
        status = None
        shippingfedex_id = shippingfedex_obj.search(cr, uid,
                                                    [('active', '=', True)])

        for sales_order in self.browse(cr, uid, ids):
            partner_id = sales_order.partner_shipping_id
            if not shippingfedex_id:
                raise osv.except_osv(_('Error'),
                                     _('Default Fedex settings not defined'))
            else:
                shippingfedex_id = shippingfedex_id[0]

            shippingfedex_ptr = shippingfedex_obj.browse(
                cr, uid, shippingfedex_id)
            account_no = shippingfedex_ptr.account_no
            key = shippingfedex_ptr.key
            password = shippingfedex_ptr.password
            meter_no = shippingfedex_ptr.meter_no
            is_test = shippingfedex_ptr.test

            CONFIG_OBJ = FedexConfig(key=key,
                                     password=password,
                                     account_number=account_no,
                                     meter_number=meter_no,
                                     use_test_server=is_test)
            connection = FedexAddressValidationRequest(CONFIG_OBJ)

            # The AddressValidationOptions are created with default values of None, which
            # will cause WSDL validation errors. To make things work, each option needs to
            # be explicitly set or deleted.

            ### Get Address from sale order

            cust_name = partner_id.name or ''
            cust_id = partner_id.id or ''

            street = partner_id.street or ''

            street2 = partner_id.street2 or ''

            city = partner_id.city or ''

            postal_code = partner_id.zip or ''

            phone = partner_id.phone or ''

            email = partner_id.email or ''

            receipient = Address(cust_name or cust_id, street, city,
                                 partner_id.state_id.code or '', postal_code,
                                 partner_id.country_id.code, street2 or '',
                                 phone or '', email or '',
                                 partner_id.company_id.name or '')

            ## Set the flags we want to True (or a value).
            connection.RequestTimestamp = datetime.datetime.now().isoformat()
            #connection.AddressValidationOptions.CheckResidentialStatus = True
            #connection.AddressValidationOptions.VerifyAddresses = True
            #connection.AddressValidationOptions.RecognizeAlternateCityNames = True
            #connection.AddressValidationOptions.MaximumNumberOfMatches = 3

            ## Delete the flags we don't want.
            #del connection.AddressValidationOptions.ConvertToUpperCase
            #del connection.AddressValidationOptions.ReturnParsedElements

            ## *Accuracy fields can be TIGHT, EXACT, MEDIUM, or LOOSE. Or deleted.
            #connection.AddressValidationOptions.StreetAccuracy = 'LOOSE'
            #del connection.AddressValidationOptions.DirectionalAccuracy
            #del connection.AddressValidationOptions.CompanyNameAccuracy

            ## Create some addresses to validate
            ### Shipper
            cust_address = sales_order.company_id
            if not cust_address:
                raise osv.except_osv(
                    _('Error'),
                    _('Shop Address not defined!'),
                )

            shipper = Address(cust_address.name or cust_address.id,
                              cust_address.street, cust_address.city,
                              cust_address.state_id.code or '',
                              cust_address.zip, cust_address.country_id.code,
                              cust_address.street2 or '', cust_address.phone
                              or '', cust_address.email, cust_address.name)

            source_address = connection.create_wsdl_object_of_type(
                'AddressToValidate')
            source_address.Address.StreetLines = shipper.address1  # ['320 S Cedros', '#200']
            source_address.Address.City = shipper.city  # 'Solana Beach'
            source_address.Address.StateOrProvinceCode = shipper.state_code  # 'CA'
            source_address.Address.PostalCode = shipper.zip  # 92075
            source_address.Address.CountryCode = shipper.country_code  # 'US'
            connection.add_address(source_address)

            sale_order_destination_address = connection.create_wsdl_object_of_type(
                'AddressToValidate')
            #sale_order_destination_address.CompanyName = receipient.company_name
            sale_order_destination_address.Address.StreetLines = receipient.address1  #['155 Old Greenville Hwy', 'Suite 103']
            sale_order_destination_address.Address.City = receipient.city  #'Clemson'
            sale_order_destination_address.Address.StateOrProvinceCode = receipient.state_code  #'SC'
            sale_order_destination_address.Address.PostalCode = receipient.zip  #29631
            sale_order_destination_address.Address.CountryCode = receipient.country_code  #'US'
            sale_order_destination_address.Address.Residential = False
            connection.add_address(sale_order_destination_address)

            try:
                ## Send the request and print the response
                connection.send_request()
                sales_order.is_test = True
                self.write(cr, uid, ids, {
                    'is_test': True,
                    'valid_note': 'Address is Valid'
                }, context)
                cr.commit()
            except Exception, e:
                sales_order.invalid_addr = False
                self.write(cr, uid, ids, {
                    'is_test': False,
                    'valid_note': 'Address is InValid'
                }, context)
                cr.commit()
                raise osv.except_osv(
                    _('Error'),
                    _('Invalid address, Please fill correct shipping address'))
            results = len(connection.response.AddressResults)
コード例 #9
0
# Create some addresses to validate
address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
address1.ClientReferenceId = "Your ID for the Recipient"
address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
address1.Address.City = 'Clemson'
address1.Address.StateOrProvinceCode = 'SC'
address1.Address.PostalCode = 29631
address1.Address.CountryCode = 'US'
address1.Address.Residential = False

address1.Contact.PersonName = 'Recipient Name'
address1.Contact.CompanyName = 'Company Name'
address1.Contact.PhoneNumber = '999-123-5343'
address1.Contact.EMailAddress = '*****@*****.**'
avs_request.add_address(address1)

address2 = avs_request.create_wsdl_object_of_type('AddressToValidate')
address2.Address.StreetLines = ['320 S Cedros', '#200']
address2.Address.City = 'Solana Beach'
address2.Address.StateOrProvinceCode = 'CA'
address2.Address.PostalCode = 92075
address2.Address.CountryCode = 'US'
avs_request.add_address(address2)

# If you'd like to see some documentation on the ship service WSDL, un-comment
# this line. (Spammy).
# print(avs_request.client)

# Un-comment this to see your complete, ready-to-send request as it stands
# before it is actually sent. This is useful for seeing what values you can
コード例 #10
0
#!/usr/bin/env python
"""
This example shows how to validate addresses. Note that the validation
class can handle up to 100 addresses for validation.
"""
import logging
from example_config import CONFIG_OBJ
from fedex.services.address_validation_service import FedexAddressValidationRequest

# Set this to the INFO level to see the response from Fedex printed in stdout.
logging.basicConfig(level=logging.INFO)

# This is the object that will be handling our tracking request.
# We're using the FedexConfig object from example_config.py in this dir.
address = FedexAddressValidationRequest(CONFIG_OBJ)

address1 = address.create_wsdl_object_of_type('AddressToValidate')
address1.CompanyName = 'International Paper'
address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
address1.Address.City = 'Clemson'
address1.Address.StateOrProvinceCode = 'SC'
address1.Address.PostalCode = 29631
address1.Address.CountryCode = 'US'
address1.Address.Residential = False

address.add_address(address1)
address.send_request()
print address.response
コード例 #11
0
# Create some addresses to validate
address1 = avs_request.create_wsdl_object_of_type('AddressToValidate')
address1.ClientReferenceId = "Your ID for the Recipient"
address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
address1.Address.City = 'Clemson'
address1.Address.StateOrProvinceCode = 'SC'
address1.Address.PostalCode = 29631
address1.Address.CountryCode = 'US'
address1.Address.Residential = False

address1.Contact.PersonName = 'Recipient Name'
address1.Contact.CompanyName = 'Company Name'
address1.Contact.PhoneNumber = '999-123-5343'
address1.Contact.EMailAddress = '*****@*****.**'
avs_request.add_address(address1)

address2 = avs_request.create_wsdl_object_of_type('AddressToValidate')
address2.Address.StreetLines = ['320 S Cedros', '#200']
address2.Address.City = 'Solana Beach'
address2.Address.StateOrProvinceCode = 'CA'
address2.Address.PostalCode = 92075
address2.Address.CountryCode = 'US'
avs_request.add_address(address2)

# If you'd like to see some documentation on the ship service WSDL, un-comment
# this line. (Spammy).
# print(avs_request.client)

# Un-comment this to see your complete, ready-to-send request as it stands
# before it is actually sent. This is useful for seeing what values you can
コード例 #12
0
del connection.AddressValidationOptions.ConvertToUpperCase
del connection.AddressValidationOptions.ReturnParsedElements

## *Accuracy fields can be TIGHT, EXACT, MEDIUM, or LOOSE. Or deleted.
connection.AddressValidationOptions.StreetAccuracy = 'LOOSE'
del connection.AddressValidationOptions.DirectionalAccuracy
del connection.AddressValidationOptions.CompanyNameAccuracy

## Create some addresses to validate
address1 = connection.create_wsdl_object_of_type('AddressToValidate')
address1.CompanyName = 'International Paper'
address1.Address.StreetLines = ['155 Old Greenville Hwy', 'Suite 103']
address1.Address.City = 'Clemson'
address1.Address.StateOrProvinceCode = 'SC'
address1.Address.PostalCode = 29631
address1.Address.CountryCode = 'US'
address1.Address.Residential = False
connection.add_address(address1)

address2 = connection.create_wsdl_object_of_type('AddressToValidate')
address2.Address.StreetLines = ['320 S Cedros', '#200']
address2.Address.City = 'Solana Beach'
address2.Address.StateOrProvinceCode = 'CA'
address2.Address.PostalCode = 92075
address2.Address.CountryCode = 'US'
connection.add_address(address2)

## Send the request and print the response
connection.send_request()
print connection.response