Skip to content

Commit 543ad68

Browse files
committed
more rc10hotfixes
1 parent 6fdade4 commit 543ad68

File tree

5 files changed

+61
-15
lines changed

5 files changed

+61
-15
lines changed

purplship/mappers/dhl/dhl_mapper/partials/rate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def create_dct_request(self, payload: T.shipment_request) -> Req.DCTRequest:
103103

104104
GetQuote = Req.GetQuoteType(
105105
Request=self.init_request(),
106-
From=Req.DCTFrom(
106+
From=ReqType.DCTFrom(
107107
CountryCode=payload.shipper.country_code,
108108
Postalcode=payload.shipper.postal_code,
109109
City=payload.shipper.city,

purplship/mappers/fedex/fedex_mapper/partials/rate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
RequestedPackageLineItem,
2121
Weight,
2222
Dimensions,
23+
RatedShipmentDetail,
2324
)
2425
from datetime import datetime
2526
from lxml import etree
@@ -49,31 +50,32 @@ def _extract_quote(
4950
detail.build(detailNode)
5051
if not detail.RatedShipmentDetails:
5152
return quotes
52-
shipmentDetail = detail.RatedShipmentDetails[0].ShipmentRateDetail
53+
shipmentDetail: RatedShipmentDetail = detail.RatedShipmentDetails[0].ShipmentRateDetail
54+
currency_ = next(c.text for c in detailNode.xpath(
55+
".//*[local-name() = $name]", name="Currency"
56+
))
5357
Discounts_ = map(
5458
lambda d: T.ChargeDetails(
55-
name=d.RateDiscountType, amount=float(d.Amount.Amount)
59+
name=d.RateDiscountType, amount=float(d.Amount.Amount), currency=currency_
5660
),
5761
shipmentDetail.FreightDiscounts,
5862
)
5963
Surcharges_ = map(
6064
lambda s: T.ChargeDetails(
61-
name=s.SurchargeType, amount=float(s.Amount.Amount)
65+
name=s.SurchargeType, amount=float(s.Amount.Amount), currency=currency_
6266
),
6367
shipmentDetail.Surcharges,
6468
)
6569
Taxes_ = map(
66-
lambda t: T.ChargeDetails(name=t.TaxType, amount=float(t.Amount.Amount)),
70+
lambda t: T.ChargeDetails(name=t.TaxType, amount=float(t.Amount.Amount), currency=currency_),
6771
shipmentDetail.Taxes,
6872
)
6973
return quotes + [
7074
T.QuoteDetails(
7175
carrier=self.client.carrier_name,
7276
service_name=detail.ServiceType,
7377
service_type=detail.ActualRateType,
74-
currency=shipmentDetail.CurrencyExchangeRate.IntoCurrency
75-
if shipmentDetail.CurrencyExchangeRate
76-
else None,
78+
currency=currency_,
7779
base_charge=float(shipmentDetail.TotalBaseCharge.Amount),
7880
total_charge=float(
7981
shipmentDetail.TotalNetChargeWithDutiesAndTaxes.Amount

purplship/mappers/ups/ups_mapper/partials/rate.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
PackagingType,
1010
ServiceOption,
1111
RatingOption,
12+
ShippingServiceCode
1213
)
1314

1415

@@ -50,10 +51,13 @@ def _extract_freight_rate(
5051
if r.Type.Code not in ["DSCNT", "AFTR_DSCNT", "DSCNT_RATE", "LND_GROSS"]
5152
]
5253
extra_charges = Discounts_ + Surcharges_
54+
currency_ = next(c.text for c in detailNode.xpath(
55+
".//*[local-name() = $name]", name="CurrencyCode"
56+
))
5357
return rates + [
5458
T.QuoteDetails(
5559
carrier=self.client.carrier_name,
56-
currency=detail.TotalShipmentCharge.CurrencyCode,
60+
currency=currency_,
5761
service_name=detail.Service.Description,
5862
service_type=detail.Service.Code,
5963
base_charge=float(detail.TotalShipmentCharge.MonetaryValue),
@@ -98,12 +102,15 @@ def _extract_package_rate(
98102
arrival.build(arrival) for arrival in
99103
detailNode.xpath(".//*[local-name() = $name]", name="Arrival")
100104
]
105+
currency_ = next(c.text for c in detailNode.xpath(
106+
".//*[local-name() = $name]", name="CurrencyCode"
107+
))
101108

102109
return rates + [
103110
T.QuoteDetails(
104111
carrier=self.client.carrier_name,
105-
currency=rate.TransportationCharges.CurrencyCode,
106-
service_name=rate.Service.Description,
112+
currency=currency_,
113+
service_name=str(ShippingServiceCode(rate.Service.Code).name),
107114
service_type=rate.Service.Code,
108115
base_charge=float(rate.TransportationCharges.MonetaryValue),
109116
total_charge=float(total_charges.MonetaryValue),

tests/fedex/quote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_parse_quote_error_response(self):
6767
"delivery_date": None,
6868
"discount": 0.0,
6969
"duties_and_taxes": 0.0,
70-
"extra_charges": [{"amount": 9.22, "currency": None, "name": "FUEL"}],
70+
"extra_charges": [{"amount": 9.22, "currency": "USD", "name": "FUEL"}],
7171
"service_name": "INTERNATIONAL_PRIORITY",
7272
"service_type": "PAYOR_ACCOUNT_SHIPMENT",
7373
"total_charge": 239.71,
@@ -79,7 +79,7 @@ def test_parse_quote_error_response(self):
7979
"delivery_date": None,
8080
"discount": 0.0,
8181
"duties_and_taxes": 0.0,
82-
"extra_charges": [{"amount": 8.3, "currency": None, "name": "FUEL"}],
82+
"extra_charges": [{"amount": 8.3, "currency": "USD", "name": "FUEL"}],
8383
"service_name": "INTERNATIONAL_ECONOMY",
8484
"service_type": "PAYOR_ACCOUNT_SHIPMENT",
8585
"total_charge": 215.77,

tests/ups/quote.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,46 @@ def test_parse_quote_missing_args_error(self):
121121
],
122122
]
123123

124-
ParsedFreightRateResponse = [[{'base_charge': 909.26, 'carrier': 'UPS', 'currency': 'USD', 'delivery_date': None, 'discount': 776.36, 'duties_and_taxes': 576.54, 'extra_charges': [{'amount': 776.36, 'currency': 'USD', 'name': 'DSCNT'}, {'amount': 480.0, 'currency': 'USD', 'name': 'HOL_WE_PU_DEL'}, {'amount': 66.54, 'currency': 'USD', 'name': '2'}, {'amount': 30.0, 'currency': 'USD', 'name': 'CA_BORDER'}], 'service_name': None, 'service_type': '309', 'total_charge': 332.72}], []]
124+
ParsedFreightRateResponse = [
125+
[
126+
{
127+
"base_charge": 909.26,
128+
"carrier": "UPS",
129+
"currency": "USD",
130+
"delivery_date": None,
131+
"discount": 776.36,
132+
"duties_and_taxes": 576.54,
133+
"extra_charges": [
134+
{"amount": 776.36, "currency": "USD", "name": "DSCNT"},
135+
{"amount": 480.0, "currency": "USD", "name": "HOL_WE_PU_DEL"},
136+
{"amount": 66.54, "currency": "USD", "name": "2"},
137+
{"amount": 30.0, "currency": "USD", "name": "CA_BORDER"},
138+
],
139+
"service_name": None,
140+
"service_type": "309",
141+
"total_charge": 332.72,
142+
}
143+
],
144+
[],
145+
]
125146

126-
ParsedRateResponse = [[{'base_charge': 9.86, 'carrier': 'UPS', 'currency': 'USD', 'delivery_date': 'None', 'discount': None, 'duties_and_taxes': 0.0, 'extra_charges': [{'amount': 0.0, 'currency': 'USD', 'name': None}], 'service_name': '', 'service_type': '03', 'total_charge': 9.86}], []]
147+
ParsedRateResponse = [
148+
[
149+
{
150+
"base_charge": 9.86,
151+
"carrier": "UPS",
152+
"currency": "USD",
153+
"delivery_date": "None",
154+
"discount": None,
155+
"duties_and_taxes": 0.0,
156+
"extra_charges": [{"amount": 0.0, "currency": "USD", "name": None}],
157+
"service_name": "UPS_Ground",
158+
"service_type": "03",
159+
"total_charge": 9.86,
160+
}
161+
],
162+
[],
163+
]
127164

128165

129166
QuoteParsingError = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

0 commit comments

Comments
 (0)