~martijnbraam/shipments

d173de94bcc1cbf0503b1ad2daf477f5b818fb61 — Martijn Braam 2 years ago af169f4
carrier: dhl: add basic identify function and bugfix
1 files changed, 13 insertions(+), 2 deletions(-)

M shipments/carrier.py
M shipments/carrier.py => shipments/carrier.py +13 -2
@@ 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