Skip to content

Commit 0b90870

Browse files
authored
Merge pull request #83 from PurplShip/purplship-2020.10.1-patch
[patch] Purplship 2020.10.1 patch
2 parents e5767e3 + ccb6f50 commit 0b90870

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

extensions/ups/purplship/providers/ups/track.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import List, Tuple
22
from pyups.common import RequestType, TransactionReferenceType
3-
from pyups.track_web_service_schema import TrackRequest, ShipmentType, ActivityType
3+
from pyups.track_web_service_schema import TrackRequest, ShipmentType, ActivityType, AddressType
44
from purplship.core.utils import export, Serializable, Element, format_date, format_time
5-
from purplship.core.utils.soap import apply_namespaceprefix, create_envelope, Envelope
5+
from purplship.core.utils.soap import apply_namespaceprefix, create_envelope, Envelope, build
66
from purplship.core.models import (
77
TrackingEvent,
88
TrackingRequest,
@@ -24,16 +24,13 @@ def parse_track_response(
2424

2525

2626
def _extract_tracking(shipment_node: Element, settings: Settings) -> TrackingDetails:
27-
track_detail = ShipmentType()
28-
track_detail.build(shipment_node)
29-
activity_nodes = shipment_node.xpath(".//*[local-name() = $name]", name="Activity")
30-
31-
def build_activity(node) -> ActivityType:
32-
activity = ActivityType()
33-
activity.build(node)
34-
return activity
27+
track_detail = build(ShipmentType, shipment_node)
28+
activities = [
29+
build(ActivityType, node)
30+
for node in
31+
shipment_node.xpath(".//*[local-name() = $name]", name="Activity")
32+
]
3533

36-
activities: List[ActivityType] = list(map(build_activity, activity_nodes))
3734
return TrackingDetails(
3835
carrier_name=settings.carrier_name,
3936
carrier_id=settings.carrier_id,
@@ -42,21 +39,28 @@ def build_activity(node) -> ActivityType:
4239
map(
4340
lambda a: TrackingEvent(
4441
date=format_date(a.Date, "%Y%m%d"),
45-
time=format_time(a.Time, "%H%M%S"),
46-
code=a.Status.Code if a.Status else None,
42+
description=a.Status.Description if a.Status else None,
4743
location=(
48-
a.ActivityLocation.Address.City
49-
if a.ActivityLocation and a.ActivityLocation.Address
50-
else None
44+
_format_location(a.ActivityLocation.Address)
45+
if a.ActivityLocation is not None and a.ActivityLocation.Address is not None else None
5146
),
52-
description=a.Status.Description if a.Status else None,
47+
time=format_time(a.Time, "%H%M%S"),
48+
code=a.Status.Code if a.Status else None,
5349
),
5450
activities,
5551
)
5652
),
5753
)
5854

5955

56+
def _format_location(address: AddressType) -> str:
57+
return ", ".join([
58+
location for location in [
59+
address.City, address.StateProvinceCode, address.CountryCode
60+
] if location is not None
61+
])
62+
63+
6064
def track_request(
6165
payload: TrackingRequest, settings: Settings
6266
) -> Serializable[List[Envelope]]:

extensions/ups/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="purplship.ups",
6-
version="2020.10.0",
6+
version="2020.10.1",
77
description="Multi-carrier shipping API integration with python",
88
url="https://github.com/PurplShip/purplship",
99
author="Purplship Team",

purplship/core/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class TrackingEvent:
275275

276276
date: str
277277
description: str
278-
location: str
278+
location: str = None
279279
code: str = None
280280
time: str = None
281281
signatory: str = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414

1515
setup(name='purplship',
16-
version='2020.10.0',
16+
version='2020.10.1',
1717
description='Multi-carrier shipping API integration with python',
1818
long_description=long_description,
1919
long_description_content_type="text/markdown",

tests/ups_package/tracking.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,42 +79,42 @@ def test_tracking_unknown_response_parsing(self):
7979
"code": "KB",
8080
"date": "2010-08-30",
8181
"description": "UPS INTERNAL ACTIVITY CODE",
82-
"location": "BONN",
82+
"location": "BONN, DE",
8383
"time": "10:39",
8484
},
8585
{
8686
"code": "DJ",
8787
"date": "2010-08-30",
8888
"description": "ADVERSE WEATHER CONDITIONS CAUSED THIS DELAY",
89-
"location": "BONN",
89+
"location": "BONN, DE",
9090
"time": "10:32",
9191
},
9292
{
9393
"code": "X",
9494
"date": "2010-09-10",
9595
"description": "THE RECEIVER'S LOCATION WAS CLOSED ON THE 2ND DELIVERY ATTEMPT. A 3RD DELIVERY ATTEMPT WILL BE MADE",
96-
"location": "ANYTOWN",
96+
"location": "ANYTOWN, GA, US",
9797
"time": "18:03",
9898
},
9999
{
100100
"code": "FS",
101101
"date": "2010-09-12",
102102
"description": "DELIVERED",
103-
"location": "ANYTOWN",
103+
"location": "ANYTOWN, GA, US",
104104
"time": "11:57",
105105
},
106106
{
107107
"code": "PU",
108108
"date": "2010-04-04",
109109
"description": "PICKUP SCAN",
110-
"location": "WEST CHESTER-MALVERN",
110+
"location": "WEST CHESTER-MALVERN, GA, US",
111111
"time": "14:40",
112112
},
113113
{
114114
"code": "KB",
115115
"date": "2010-08-30",
116116
"description": "UPS INTERNAL ACTIVITY CODE",
117-
"location": "BONN",
117+
"location": "BONN, DE",
118118
"time": "13:13",
119119
},
120120
],

0 commit comments

Comments
 (0)