From d173de94bcc1cbf0503b1ad2daf477f5b818fb61 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Tue, 30 Nov 2021 02:52:05 +0100 Subject: [PATCH] carrier: dhl: add basic identify function and bugfix --- shipments/carrier.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/shipments/carrier.py b/shipments/carrier.py index b3e7a25..b4ffa7d 100644 --- a/shipments/carrier.py +++ b/shipments/carrier.py @@ -371,12 +371,23 @@ class InPost(Carrier): class DHL(Carrier): DISPLAYNAME = 'DHL' + @classmethod + def identify(cls, code): + # DHL Parcel + if code.startswith('3S') or code.startswith('JVGL'): + if len(code) == 14: + return True + + # DHL Express codes are very non-unique. Described as 10 digit numerical + return False + def _addr(self, payload): res = Address() if 'countryCode' in payload['address']: res.country = payload['address']['countryCode'] return res + @classmethod def get_requirements(cls, code): return [ ('apikey', 'DHL API key', 'text'), @@ -427,10 +438,10 @@ class DHL(Carrier): e = PackageEvent(stamp, location, event['status']) result.events.append(e) - if 'address' in payload['origin']: + if 'origin' in payload and 'address' in payload['origin']: result.origin = self._addr(payload['origin']) - if 'address' in payload['destination']: + if 'destination' in payload and 'address' in payload['destination']: result.destination = self._addr(payload['destination']) return result -- 2.45.2