From c8b73061924992d6dde860fb4732a77e50ae4039 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Mon, 10 Jan 2022 02:37:55 +0100 Subject: [PATCH] carrier: dhl: fix status attribute in events --- shipments/carrier.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shipments/carrier.py b/shipments/carrier.py index dda18a5..f7cd99f 100644 --- a/shipments/carrier.py +++ b/shipments/carrier.py @@ -432,6 +432,8 @@ class DHL(Carrier): result.status_category = StatusCategory.LABEL_CREATED elif payload['status']['statusCode'] == 'transit': result.status_category = StatusCategory.IN_TRANSIT + elif payload['status']['statusCode'] == 'delivered': + result.status_category = StatusCategory.DELIVERED if 'weight' in payload['details'] and payload['details']['weight'] is not None: w = payload['details']['weight'] @@ -446,7 +448,13 @@ class DHL(Carrier): if 'location' in event: if len(event['location']['address']) == 1 and 'addressLocality' in event['location']['address']: location = event['location']['address']['addressLocality'] - e = PackageEvent(stamp, location, event['status']) + if 'status' in event: + status = event['status'] + elif 'description' in event: + status = event['description'] + else: + raise ValueError("Event without status or description") + e = PackageEvent(stamp, location, status) result.events.append(e) if 'origin' in payload and 'address' in payload['origin']: -- 2.45.2