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 track shipments by providing a tracking
14 number or other identifying features. By default, you
15 can simply pass a tracking number to the constructor. If you would like
16 to query shipments based on something other than tracking number, you will
17 want to read the documentation for the L{__init__} method.
18 Particularly, the tracking_value and package_identifier arguments.
19 """
20 - def __init__(self, config_obj, *args, **kwargs):
21 """
22 Sends a shipment tracking request. The optional keyword args
23 detailed on L{FedexBaseService} apply here as well.
24
25 @type config_obj: L{FedexConfig}
26 @param config_obj: A valid FedexConfig object.
27 """
28 self._config_obj = config_obj
29
30
31 self._version_info = {'service_id': 'ship', 'major': '7',
32 'intermediate': '0', 'minor': '0'}
33
34 self.RequestedShipment = None
35 """@ivar: Holds the RequestedShipment WSDL object."""
36
37 super(FedexProcessShipmentRequest, self).__init__(self._config_obj,
38 'ShipService_v7.wsdl',
39 *args, **kwargs)
40
42 """
43 This is the data that will be used to create your shipment. Create
44 the data structure and get it ready for the WSDL request.
45 """
46
47 self.RequestedShipment = self.client.factory.create('RequestedShipment')
48 self.RequestedShipment.ShipTimestamp = datetime.now()
49
50 TotalWeight = self.client.factory.create('Weight')
51
52 TotalWeight.Value = 0.0
53
54 TotalWeight.Units = 'LB'
55
56
57 self.RequestedShipment.TotalWeight = TotalWeight
58
59
60 ShipperParty = self.client.factory.create('Party')
61 ShipperParty.Address = self.client.factory.create('Address')
62 ShipperParty.Contact = self.client.factory.create('Contact')
63
64
65 self.RequestedShipment.Shipper = ShipperParty
66
67
68 RecipientParty = self.client.factory.create('Party')
69 RecipientParty.Contact = self.client.factory.create('Contact')
70 RecipientParty.Address = self.client.factory.create('Address')
71
72
73 self.RequestedShipment.Recipient = RecipientParty
74
75 Payor = self.client.factory.create('Payor')
76
77 Payor.AccountNumber = self._config_obj.account_number
78
79 Payor.CountryCode = 'US'
80
81 ShippingChargesPayment = self.client.factory.create('Payment')
82 ShippingChargesPayment.Payor = Payor
83
84 self.RequestedShipment.ShippingChargesPayment = ShippingChargesPayment
85 self.RequestedShipment.LabelSpecification = self.client.factory.create('LabelSpecification')
86
87 self.RequestedShipment.RateRequestTypes = ['ACCOUNT']
88
89
90 self.RequestedShipment.PackageCount = 0
91 self.RequestedShipment.RequestedPackageLineItems = []
92
93
94
95 self.logger.debug(self.RequestedShipment)
96
98 """
99 This is very similar to just sending the shipment via the typical
100 send_request() function, but this doesn't create a shipment. It is
101 used to make sure "good" values are given by the user or the
102 application using the library.
103 """
104 self.send_request(send_function=self._assemble_and_send_validation_request)
105
107 """
108 Fires off the Fedex request.
109
110 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
111 ON FedexBaseService AND IS INHERITED.
112 """
113
114 response = self.client.service.processShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
115 ClientDetail=self.ClientDetail,
116 TransactionDetail=self.TransactionDetail,
117 Version=self.VersionId,
118 RequestedShipment=self.RequestedShipment)
119 return response
120
122 """
123 Fires off the Fedex request.
124
125 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
126 ON FedexBaseService AND IS INHERITED.
127 """
128
129 response = self.client.service.processShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
130 ClientDetail=self.ClientDetail,
131 TransactionDetail=self.TransactionDetail,
132 Version=self.VersionId,
133 RequestedShipment=self.RequestedShipment)
134 return response
135
137 """
138 Adds a package to the ship request.
139
140 @type package_item: WSDL object, type of RequestedPackageLineItem
141 WSDL object.
142 @keyword package_item: A RequestedPackageLineItem, created by
143 calling create_wsdl_object_of_type('RequestedPackageLineItem') on
144 this ShipmentRequest object. See examples/create_shipment.py for
145 more details.
146 """
147 self.RequestedShipment.RequestedPackageLineItems.append(package_item)
148 package_weight = package_item.Weight.Value
149 self.RequestedShipment.TotalWeight.Value += package_weight
150 self.RequestedShipment.PackageCount += 1
151
153 """
154 This class allows you to delete a shipment, given a tracking number.
155 """
156 - def __init__(self, config_obj, *args, **kwargs):
157 """
158 Deletes a shipment via a tracking number.
159 """
160 self._config_obj = config_obj
161
162
163 self._version_info = {'service_id': 'ship', 'major': '7',
164 'intermediate': '0', 'minor': '0'}
165 self.DeletionControlType = None
166 """@ivar: Holds the DeletrionControlType WSDL object."""
167 self.TrackingId = None
168 """@ivar: Holds the TrackingId WSDL object."""
169
170 super(FedexDeleteShipmentRequest, self).__init__(self._config_obj,
171 'ShipService_v7.wsdl',
172 *args, **kwargs)
173
175 """
176 Preps the WSDL data structures for the user.
177 """
178 self.DeletionControlType = self.client.factory.create('DeletionControlType')
179 self.TrackingId = self.client.factory.create('TrackingId')
180 self.TrackingId.TrackingIdType = self.client.factory.create('TrackingIdType')
181
183 """
184 Fires off the Fedex request.
185
186 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
187 ON FedexBaseService AND IS INHERITED.
188 """
189 client = self.client
190
191 response = client.service.deleteShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
192 ClientDetail=self.ClientDetail,
193 TransactionDetail=self.TransactionDetail,
194 Version=self.VersionId,
195 ShipTimestamp = datetime.now(),
196 TrackingId=self.TrackingId,
197 DeletionControl=self.DeletionControlType)
198
199 return response
200