Skip to content

Commit

Permalink
more rc10hotfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danh91 committed Feb 21, 2019
1 parent d027a5f commit 16826ad
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion purplship/mappers/dhl/dhl_mapper/partials/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def create_dct_request(self, payload: T.shipment_request) -> Req.DCTRequest:

GetQuote = Req.GetQuoteType(
Request=self.init_request(),
From=Req.DCTFrom(
From=ReqType.DCTFrom(
CountryCode=payload.shipper.country_code,
Postalcode=payload.shipper.postal_code,
City=payload.shipper.city,
Expand Down
16 changes: 9 additions & 7 deletions purplship/mappers/fedex/fedex_mapper/partials/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RequestedPackageLineItem,
Weight,
Dimensions,
RatedShipmentDetail,
)
from datetime import datetime
from lxml import etree
Expand Down Expand Up @@ -49,31 +50,32 @@ def _extract_quote(
detail.build(detailNode)
if not detail.RatedShipmentDetails:
return quotes
shipmentDetail = detail.RatedShipmentDetails[0].ShipmentRateDetail
shipmentDetail: RatedShipmentDetail = detail.RatedShipmentDetails[0].ShipmentRateDetail
currency_ = next(c.text for c in detailNode.xpath(
".//*[local-name() = $name]", name="Currency"
))
Discounts_ = map(
lambda d: T.ChargeDetails(
name=d.RateDiscountType, amount=float(d.Amount.Amount)
name=d.RateDiscountType, amount=float(d.Amount.Amount), currency=currency_
),
shipmentDetail.FreightDiscounts,
)
Surcharges_ = map(
lambda s: T.ChargeDetails(
name=s.SurchargeType, amount=float(s.Amount.Amount)
name=s.SurchargeType, amount=float(s.Amount.Amount), currency=currency_
),
shipmentDetail.Surcharges,
)
Taxes_ = map(
lambda t: T.ChargeDetails(name=t.TaxType, amount=float(t.Amount.Amount)),
lambda t: T.ChargeDetails(name=t.TaxType, amount=float(t.Amount.Amount), currency=currency_),
shipmentDetail.Taxes,
)
return quotes + [
T.QuoteDetails(
carrier=self.client.carrier_name,
service_name=detail.ServiceType,
service_type=detail.ActualRateType,
currency=shipmentDetail.CurrencyExchangeRate.IntoCurrency
if shipmentDetail.CurrencyExchangeRate
else None,
currency=currency_,
base_charge=float(shipmentDetail.TotalBaseCharge.Amount),
total_charge=float(
shipmentDetail.TotalNetChargeWithDutiesAndTaxes.Amount
Expand Down
13 changes: 10 additions & 3 deletions purplship/mappers/ups/ups_mapper/partials/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PackagingType,
ServiceOption,
RatingOption,
ShippingServiceCode
)


Expand Down Expand Up @@ -50,10 +51,13 @@ def _extract_freight_rate(
if r.Type.Code not in ["DSCNT", "AFTR_DSCNT", "DSCNT_RATE", "LND_GROSS"]
]
extra_charges = Discounts_ + Surcharges_
currency_ = next(c.text for c in detailNode.xpath(
".//*[local-name() = $name]", name="CurrencyCode"
))
return rates + [
T.QuoteDetails(
carrier=self.client.carrier_name,
currency=detail.TotalShipmentCharge.CurrencyCode,
currency=currency_,
service_name=detail.Service.Description,
service_type=detail.Service.Code,
base_charge=float(detail.TotalShipmentCharge.MonetaryValue),
Expand Down Expand Up @@ -98,12 +102,15 @@ def _extract_package_rate(
arrival.build(arrival) for arrival in
detailNode.xpath(".//*[local-name() = $name]", name="Arrival")
]
currency_ = next(c.text for c in detailNode.xpath(
".//*[local-name() = $name]", name="CurrencyCode"
))

return rates + [
T.QuoteDetails(
carrier=self.client.carrier_name,
currency=rate.TransportationCharges.CurrencyCode,
service_name=rate.Service.Description,
currency=currency_,
service_name=str(ShippingServiceCode(rate.Service.Code).name),
service_type=rate.Service.Code,
base_charge=float(rate.TransportationCharges.MonetaryValue),
total_charge=float(total_charges.MonetaryValue),
Expand Down
4 changes: 2 additions & 2 deletions tests/fedex/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_parse_quote_error_response(self):
"delivery_date": None,
"discount": 0.0,
"duties_and_taxes": 0.0,
"extra_charges": [{"amount": 9.22, "currency": None, "name": "FUEL"}],
"extra_charges": [{"amount": 9.22, "currency": "USD", "name": "FUEL"}],
"service_name": "INTERNATIONAL_PRIORITY",
"service_type": "PAYOR_ACCOUNT_SHIPMENT",
"total_charge": 239.71,
Expand All @@ -79,7 +79,7 @@ def test_parse_quote_error_response(self):
"delivery_date": None,
"discount": 0.0,
"duties_and_taxes": 0.0,
"extra_charges": [{"amount": 8.3, "currency": None, "name": "FUEL"}],
"extra_charges": [{"amount": 8.3, "currency": "USD", "name": "FUEL"}],
"service_name": "INTERNATIONAL_ECONOMY",
"service_type": "PAYOR_ACCOUNT_SHIPMENT",
"total_charge": 215.77,
Expand Down
41 changes: 39 additions & 2 deletions tests/ups/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,46 @@ def test_parse_quote_missing_args_error(self):
],
]

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}], []]
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,
}
],
[],
]

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}], []]
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": "UPS_Ground",
"service_type": "03",
"total_charge": 9.86,
}
],
[],
]


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

0 comments on commit 16826ad

Please sign in to comment.