1 """
2 Ship Service Module
3 ===================
4 This package contains the shipping methods defined by Fedex's
5 ShipService WSDL file. Each is encapsulated in a class for easy access.
6 For more details on each, refer to the respective class's documentation.
7 """
8 from datetime import datetime
9 from .. base_service import FedexBaseService
10
12 """
13 This class allows you to process (create) a new FedEx shipment. You will
14 need to populate the data structures in self.RequestedShipment, then
15 send the request. Label printing is supported and very configurable,
16 returning an ASCII representation with the response as well.
17 """
18 - def __init__(self, config_obj, *args, **kwargs):
19 """
20 The optional keyword args detailed on L{FedexBaseService}
21 apply here as well.
22
23 @type config_obj: L{FedexConfig}
24 @param config_obj: A valid FedexConfig object.
25 """
26 self._config_obj = config_obj
27
28
29 self._version_info = {'service_id': 'ship', 'major': '7',
30 'intermediate': '0', 'minor': '0'}
31
32 self.RequestedShipment = None
33 """@ivar: Holds the RequestedShipment WSDL object."""
34
35 super(FedexProcessShipmentRequest, self).__init__(self._config_obj,
36 'ShipService_v7.wsdl',
37 *args, **kwargs)
38
40 """
41 This is the data that will be used to create your shipment. Create
42 the data structure and get it ready for the WSDL request.
43 """
44
45 self.RequestedShipment = self.client.factory.create('RequestedShipment')
46 self.RequestedShipment.ShipTimestamp = datetime.now()
47
48 TotalWeight = self.client.factory.create('Weight')
49
50 TotalWeight.Value = 0.0
51
52 TotalWeight.Units = 'LB'
53
54
55 self.RequestedShipment.TotalWeight = TotalWeight
56
57
58 ShipperParty = self.client.factory.create('Party')
59 ShipperParty.Address = self.client.factory.create('Address')
60 ShipperParty.Contact = self.client.factory.create('Contact')
61
62
63 self.RequestedShipment.Shipper = ShipperParty
64
65
66 RecipientParty = self.client.factory.create('Party')
67 RecipientParty.Contact = self.client.factory.create('Contact')
68 RecipientParty.Address = self.client.factory.create('Address')
69
70
71 self.RequestedShipment.Recipient = RecipientParty
72
73 Payor = self.client.factory.create('Payor')
74
75 Payor.AccountNumber = self._config_obj.account_number
76
77 Payor.CountryCode = 'US'
78
79 ShippingChargesPayment = self.client.factory.create('Payment')
80 ShippingChargesPayment.Payor = Payor
81
82 self.RequestedShipment.ShippingChargesPayment = ShippingChargesPayment
83 self.RequestedShipment.LabelSpecification = self.client.factory.create('LabelSpecification')
84
85 self.RequestedShipment.RateRequestTypes = ['ACCOUNT']
86
87
88 self.RequestedShipment.PackageCount = 0
89 self.RequestedShipment.RequestedPackageLineItems = []
90
91
92
93 self.logger.debug(self.RequestedShipment)
94
96 """
97 This is very similar to just sending the shipment via the typical
98 send_request() function, but this doesn't create a shipment. It is
99 used to make sure "good" values are given by the user or the
100 application using the library.
101 """
102 self.send_request(send_function=self._assemble_and_send_validation_request)
103
105 """
106 Fires off the Fedex shipment validation request.
107
108 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL
109 send_validation_request(), WHICH RESIDES ON FedexBaseService
110 AND IS INHERITED.
111 """
112
113 response = self.client.service.validateShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
114 ClientDetail=self.ClientDetail,
115 TransactionDetail=self.TransactionDetail,
116 Version=self.VersionId,
117 RequestedShipment=self.RequestedShipment)
118 return response
119
121 """
122 Fires off the Fedex request.
123
124 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(),
125 WHICH RESIDES ON FedexBaseService AND IS INHERITED.
126 """
127
128 response = self.client.service.processShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
129 ClientDetail=self.ClientDetail,
130 TransactionDetail=self.TransactionDetail,
131 Version=self.VersionId,
132 RequestedShipment=self.RequestedShipment)
133 return response
134
136 """
137 Adds a package to the ship request.
138
139 @type package_item: WSDL object, type of RequestedPackageLineItem
140 WSDL object.
141 @keyword package_item: A RequestedPackageLineItem, created by
142 calling create_wsdl_object_of_type('RequestedPackageLineItem') on
143 this ShipmentRequest object. See examples/create_shipment.py for
144 more details.
145 """
146 self.RequestedShipment.RequestedPackageLineItems.append(package_item)
147 package_weight = package_item.Weight.Value
148 self.RequestedShipment.TotalWeight.Value += package_weight
149 self.RequestedShipment.PackageCount += 1
150
152 """
153 This class allows you to delete a shipment, given a tracking number.
154 """
155 - def __init__(self, config_obj, *args, **kwargs):
156 """
157 Deletes a shipment via a tracking number.
158 """
159 self._config_obj = config_obj
160
161
162 self._version_info = {'service_id': 'ship', 'major': '7',
163 'intermediate': '0', 'minor': '0'}
164 self.DeletionControlType = None
165 """@ivar: Holds the DeletrionControlType WSDL object."""
166 self.TrackingId = None
167 """@ivar: Holds the TrackingId WSDL object."""
168
169 super(FedexDeleteShipmentRequest, self).__init__(self._config_obj,
170 'ShipService_v7.wsdl',
171 *args, **kwargs)
172
174 """
175 Preps the WSDL data structures for the user.
176 """
177 self.DeletionControlType = self.client.factory.create('DeletionControlType')
178 self.TrackingId = self.client.factory.create('TrackingId')
179 self.TrackingId.TrackingIdType = self.client.factory.create('TrackingIdType')
180
182 """
183 Fires off the Fedex request.
184
185 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
186 ON FedexBaseService AND IS INHERITED.
187 """
188 client = self.client
189
190 response = client.service.deleteShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
191 ClientDetail=self.ClientDetail,
192 TransactionDetail=self.TransactionDetail,
193 Version=self.VersionId,
194 ShipTimestamp = datetime.now(),
195 TrackingId=self.TrackingId,
196 DeletionControl=self.DeletionControlType)
197
198 return response
199