~serpent-consulting-services/openerp-usa/shipping_api_6-1

« back to all changes in this revision

Viewing changes to partner_address_validation/fedex/services/package_movement.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Package Movement Information Service
3
 
====================================
4
 
This package contains classes to check service availability, route, and postal
5
 
codes. Defined by the PackageMovementInformationService WSDL file. 
6
 
"""
7
 
import logging
8
 
from .. base_service import FedexBaseService, FedexError
9
 
 
10
 
class FedexPostalCodeNotFound(FedexError):
11
 
    """
12
 
    Exception: Sent when the postalcode is missing.
13
 
    """
14
 
    pass
15
 
 
16
 
class FedexInvalidPostalCodeFormat(FedexError):
17
 
    """
18
 
    Exception: Sent when the postal code is invalid
19
 
    """
20
 
    pass
21
 
 
22
 
class PostalCodeInquiryRequest(FedexBaseService):
23
 
    """
24
 
    The postal code inquiry enables customers to validate postal codes
25
 
    and service commitments.
26
 
    """
27
 
    def __init__(self, config_obj, postal_code=None, country_code=None, *args, **kwargs):
28
 
        """
29
 
        Sets up an inquiry request. The optional keyword args
30
 
        detailed on L{FedexBaseService} apply here as well.
31
 
        
32
 
        @type config_obj: L{FedexConfig}
33
 
        @param config_obj: A valid FedexConfig object
34
 
        @param postal_code: a valid postal code
35
 
        @param country_code: ISO country code to which the postal code belongs to.
36
 
        """
37
 
        self._config_obj = config_obj
38
 
        
39
 
        # Holds version info for the VersionId SOAP object.
40
 
        self._version_info = {'service_id': 'pmis', 'major': '4',
41
 
                             'intermediate': '0', 'minor': '0'}
42
 
        self.PostalCode = postal_code
43
 
        self.CountryCode = country_code
44
 
       
45
 
       
46
 
        # Call the parent FedexBaseService class for basic setup work.
47
 
        super(PostalCodeInquiryRequest, self).__init__(self._config_obj,
48
 
                                                'PackageMovementInformationService_v4.wsdl',
49
 
                                                *args, **kwargs)
50
 
        
51
 
 
52
 
    def _check_response_for_request_errors(self):
53
 
        """
54
 
        Checks the response to see if there were any errors specific to
55
 
        this WSDL.
56
 
        """
57
 
        if self.response.HighestSeverity == "ERROR":
58
 
            for notification in self.response.Notifications:
59
 
                if notification.Severity == "ERROR":
60
 
                    if "Postal Code Not Found" in notification.Message:
61
 
                        raise FedexPostalCodeNotFound(notification.Code,
62
 
                                                         notification.Message)
63
 
 
64
 
                    elif "Invalid Postal Code Format" in self.response.Notifications:
65
 
                        raise FedexInvalidPostalCodeFormat(notification.Code,
66
 
                                                         notification.Message)
67
 
                    else:
68
 
                        raise FedexError(notification.Code,
69
 
                                         notification.Message)
70
 
                                         
71
 
    def _prepare_wsdl_objects(self):
72
 
        pass
73
 
 
74
 
        
75
 
    def _assemble_and_send_request(self):
76
 
        """
77
 
        Fires off the Fedex request.
78
 
        
79
 
        @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
80
 
            ON FedexBaseService AND IS INHERITED.
81
 
        """
82
 
        client = self.client
83
 
        
84
 
       
85
 
        # We get an exception like this when specifying an IntegratorId:
86
 
        # suds.TypeNotFound: Type not found: 'IntegratorId'
87
 
        # Setting it to None does not seem to appease it.
88
 
        
89
 
        del self.ClientDetail.IntegratorId
90
 
        
91
 
        # Fire off the query.
92
 
        response = client.service.postalCodeInquiry(WebAuthenticationDetail=self.WebAuthenticationDetail,
93
 
                                        ClientDetail=self.ClientDetail,
94
 
                                        TransactionDetail=self.TransactionDetail,
95
 
                                        Version=self.VersionId,
96
 
                                        PostalCode = self.PostalCode,
97
 
                                        CountryCode = self.CountryCode)
98
 
 
99
 
        return response
100
 
        
 
 
b'\\ No newline at end of file'