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
9 import datetime
10 from ..base_service import FedexBaseService
11
12
14 """
15 This class allows you to get the shipping charges for a particular address.
16 You will need to populate the data structures in self.RequestedShipment,
17 then send the request.
18 """
19
20 - def __init__(self, config_obj, *args, **kwargs):
21 """
22 The optional keyword args detailed on L{FedexBaseService}
23 apply here as well.
24
25 @type config_obj: L{FedexConfig}
26 @param config_obj: A valid FedexConfig object.
27 """
28
29 self._config_obj = config_obj
30
31
32 self._version_info = {'service_id': 'crs', 'major': '18',
33 'intermediate': '0', 'minor': '0'}
34
35 self.RequestedShipment = None
36 """@ivar: Holds the RequestedShipment WSDL object including the shipper, recipient and shipt time."""
37
38 super(FedexRateServiceRequest, self).__init__(
39 self._config_obj, 'RateService_v18.wsdl', *args, **kwargs)
40 self.ClientDetail.Region = config_obj.express_region_code
41 """@ivar: Holds the express region code from the config object."""
42
44 """
45 This is the data that will be used to create your shipment. Create
46 the data structure and get it ready for the WSDL request.
47 """
48
49
50 self.ReturnTransitAndCommit = False
51
52
53 self.RequestedShipment = self.client.factory.create('RequestedShipment')
54 self.RequestedShipment.ShipTimestamp = datetime.datetime.now()
55
56
57 total_weight = self.client.factory.create('Weight')
58
59 total_weight.Value = 0.0
60
61 total_weight.Units = 'LB'
62
63
64 self.RequestedShipment.TotalWeight = total_weight
65
66
67 shipper = self.client.factory.create('Party')
68 shipper.Address = self.client.factory.create('Address')
69 shipper.Contact = self.client.factory.create('Contact')
70
71
72 self.RequestedShipment.Shipper = shipper
73
74
75 recipient_party = self.client.factory.create('Party')
76 recipient_party.Contact = self.client.factory.create('Contact')
77 recipient_party.Address = self.client.factory.create('Address')
78
79 self.RequestedShipment.Recipient = recipient_party
80
81
82 self.RequestedShipment.ShippingChargesPayment = self.create_wsdl_object_of_type('Payment')
83 self.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER'
84
85
86 self.RequestedShipment.PackageCount = 0
87 self.RequestedShipment.RequestedPackageLineItems = []
88
89
90
91 self.logger.debug(self.RequestedShipment)
92
94 """
95 Fires off the Fedex request.
96
97 @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(),
98 WHICH RESIDES ON FedexBaseService AND IS INHERITED.
99 """
100
101
102 return self.client.service.getRates(
103 WebAuthenticationDetail=self.WebAuthenticationDetail,
104 ClientDetail=self.ClientDetail,
105 TransactionDetail=self.TransactionDetail,
106 Version=self.VersionId,
107 RequestedShipment=self.RequestedShipment,
108 ReturnTransitAndCommit=self.ReturnTransitAndCommit)
109
111 """
112 Adds a package to the ship request.
113
114 @type package_item: WSDL object, type of RequestedPackageLineItem
115 WSDL object.
116 @keyword package_item: A RequestedPackageLineItem, created by
117 calling create_wsdl_object_of_type('RequestedPackageLineItem') on
118 this ShipmentRequest object. See examples/create_shipment.py for
119 more details.
120 """
121
122 self.RequestedShipment.RequestedPackageLineItems.append(package_item)
123 package_weight = package_item.Weight.Value
124 self.RequestedShipment.TotalWeight.Value += package_weight
125 self.RequestedShipment.PackageCount += 1
126