1 """
2 Rate Service Module
3 ===================
4 This package contains classes to request pre-ship rating information and to
5 determine estimated or courtesy billing quotes. Time in Transit can be
6 returned with the rates if it is specified in the request.
7 """
8 from datetime import datetime
9 from .. base_service import FedexBaseService
10
12 """
13 This class allows you to get the shipping charges for a particular address.
14 You will need to populate the data structures in self.RequestedShipment,
15 then send the request.
16 """
17 - def __init__(self, config_obj, *args, **kwargs):
18 """
19 The optional keyword args detailed on L{FedexBaseService}
20 apply here as well.
21
22 @type config_obj: L{FedexConfig}
23 @param config_obj: A valid FedexConfig object.
24 """
25 self._config_obj = config_obj
26
27
28 self._version_info = {'service_id': 'crs', 'major': '8',
29 'intermediate': '0', 'minor': '0'}
30
31 self.RequestedShipment = None
32 """@ivar: Holds the RequestedShipment WSDL object."""
33
34 super(FedexRateServiceRequest, self).__init__(self._config_obj,
35 'RateService_v8.wsdl',
36 *args, **kwargs)
37
39 """
40 This is the data that will be used to create your shipment. Create
41 the data structure and get it ready for the WSDL request.
42 """
43
44 self.RequestedShipment = self.client.factory.create('RequestedShipment')
45 self.RequestedShipment.ShipTimestamp = datetime.now()
46
47 TotalWeight = self.client.factory.create('Weight')
48
49 TotalWeight.Value = 0.0
50
51 TotalWeight.Units = 'LB'
52
53
54 self.RequestedShipment.TotalWeight = TotalWeight
55
56
57 ShipperParty = self.client.factory.create('Party')
58 ShipperParty.Address = self.client.factory.create('Address')
59 ShipperParty.Contact = self.client.factory.create('Contact')
60
61
62 self.RequestedShipment.Shipper = ShipperParty
63
64
65 RecipientParty = self.client.factory.create('Party')
66 RecipientParty.Contact = self.client.factory.create('Contact')
67 RecipientParty.Address = self.client.factory.create('Address')
68
69
70 self.RequestedShipment.Recipient = RecipientParty
71
72 Payor = self.client.factory.create('Payor')
73
74 Payor.AccountNumber = self._config_obj.account_number
75
76 Payor.CountryCode = 'US'
77
78 ShippingChargesPayment = self.client.factory.create('Payment')
79 ShippingChargesPayment.Payor = Payor
80
81 self.RequestedShipment.ShippingChargesPayment = ShippingChargesPayment
82
83
84 self.RequestedShipment.RateRequestTypes = ['ACCOUNT']
85
86
87 self.RequestedShipment.PackageCount = 0
88 self.RequestedShipment.RequestedPackageLineItems = []
89
90
91
92 self.logger.debug(self.RequestedShipment)
93
94
95
96
98 """
99 Fires off the Fedex request.
100
101 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(),
102 WHICH RESIDES ON FedexBaseService AND IS INHERITED.
103 """
104
105 response = self.client.service.getRates(WebAuthenticationDetail=self.WebAuthenticationDetail,
106 ClientDetail=self.ClientDetail,
107 TransactionDetail=self.TransactionDetail,
108 Version=self.VersionId,
109 RequestedShipment=self.RequestedShipment)
110 return response
111
113 """
114 Adds a package to the ship request.
115
116 @type package_item: WSDL object, type of RequestedPackageLineItem
117 WSDL object.
118 @keyword package_item: A RequestedPackageLineItem, created by
119 calling create_wsdl_object_of_type('RequestedPackageLineItem') on
120 this ShipmentRequest object. See examples/create_shipment.py for
121 more details.
122 """
123 self.RequestedShipment.RequestedPackageLineItems.append(package_item)
124 package_weight = package_item.Weight.Value
125 self.RequestedShipment.TotalWeight.Value += package_weight
126 self.RequestedShipment.PackageCount += 1
127