[FIX] delivery_ups_hibou: errors when no negotiated rates

This commit is contained in:
Jared Kipe
2022-09-30 18:56:47 +00:00
parent 7d0a537bde
commit 80598885d1

View File

@@ -144,8 +144,11 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
res = {} res = {}
res['service_code'] = rated_shipment.Service.Code res['service_code'] = rated_shipment.Service.Code
res['currency_code'] = rated_shipment.TotalCharges.CurrencyCode res['currency_code'] = rated_shipment.TotalCharges.CurrencyCode
negotiated_rate = 'NegotiatedRateCharges' in rated_shipment and rated_shipment.NegotiatedRateCharges.TotalCharge.MonetaryValue or None negotiated_rate = None
if 'NegotiatedRateCharges' in rated_shipment and rated_shipment.NegotiatedRateCharges and \
'TotalCharge' in rated_shipment.NegotiatedRateCharges and rated_shipment.NegotiatedRateCharges.TotalCharge:
negotiated_rate = rated_shipment.NegotiatedRateCharges.TotalCharge.MonetaryValue
res['price'] = negotiated_rate or rated_shipment.TotalCharges.MonetaryValue res['price'] = negotiated_rate or rated_shipment.TotalCharges.MonetaryValue
# Hibou Delivery # Hibou Delivery
if hasattr(rated_shipment, 'GuaranteedDelivery') and hasattr(rated_shipment.GuaranteedDelivery, 'BusinessDaysInTransit'): if hasattr(rated_shipment, 'GuaranteedDelivery') and hasattr(rated_shipment.GuaranteedDelivery, 'BusinessDaysInTransit'):
@@ -205,22 +208,27 @@ def patched_get_shipping_price(self, shipment_info, packages, shipper, ship_from
break break
result.append(res) result.append(res)
else: else:
result = {} # Check if ProcessRate is not success then return reason for that
result['currency_code'] = response.RatedShipment[0].TotalCharges.CurrencyCode if response.Response.ResponseStatus.Code != "1":
return self.get_error_message(response.Response.ResponseStatus.Code, response.Response.ResponseStatus.Description)
rate = response.RatedShipment[0]
charge = rate.TotalCharges
# Some users are qualified to receive negotiated rates # Some users are qualified to receive negotiated rates
negotiated_rate = 'NegotiatedRateCharges' in response.RatedShipment[0] and response.RatedShipment[ if 'NegotiatedRateCharges' in rate and rate.NegotiatedRateCharges and rate.NegotiatedRateCharges.TotalCharge.MonetaryValue:
0].NegotiatedRateCharges.TotalCharge.MonetaryValue or None charge = rate.NegotiatedRateCharges.TotalCharge
result['price'] = negotiated_rate or response.RatedShipment[0].TotalCharges.MonetaryValue result = {
'currency_code': charge.CurrencyCode,
'price': charge.MonetaryValue,
}
# Hibou Delivery # Hibou Delivery
if hasattr(response.RatedShipment[0], 'GuaranteedDelivery') and hasattr(response.RatedShipment[0].GuaranteedDelivery, 'BusinessDaysInTransit'): if hasattr(response.RatedShipment[0], 'GuaranteedDelivery') and hasattr(response.RatedShipment[0].GuaranteedDelivery, 'BusinessDaysInTransit'):
result['transit_days'] = int(response.RatedShipment[0].GuaranteedDelivery.BusinessDaysInTransit) result['transit_days'] = int(response.RatedShipment[0].GuaranteedDelivery.BusinessDaysInTransit)
if not result.get('transit_days') and date_planned: if not result.get('transit_days') and date_planned:
# use TNT API to # use TNT API to
_logger.warning(' We would now use the TNT service. But who would show the transit days? 2') _logger.warning(' We would now use the TNT service. But who would show the transit days? 2')
return result return result
except Fault as e: except Fault as e: