The shop's order status from Tern's (needs from the docs: D5 held)
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..2dc2226 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -2,7 +2,18 @@
from datetime import date
from shop.cart import Cart
-from shop.orders import Order
+from shop import tern
+from shop.orders import (Order, CANCELLED, DELIVERED, PROBLEM, PROCESSING, SHIPPED)
+
+_TERN_STATUS = {
+ "booked": PROCESSING,
+ "collected": SHIPPED,
+ "in_transit": SHIPPED,
+ "held": SHIPPED, # at customs: normal, the parcel is still on its way
+ "delivered": DELIVERED,
+ "returned": PROBLEM,
+ "cancelled": CANCELLED,
+}
def quote_at_checkout(cart: Cart, postcode: str) -> int:
@@ -27,8 +38,12 @@ def shipments_since(day: date) -> list[dict]:
def order_status(shipment_id: str) -> str:
- """The shop's status (one of shop.orders.STATUSES) for the order whose Tern shipment this is."""
- raise NotImplementedError
+ """The shop's status (one of shop.orders.STATUSES) for the order whose Tern shipment this is.
+ A status we don't recognise is PROBLEM, so a person looks at it."""
+ code, body = tern.call("GET", f"/v2/shipments/{shipment_id}")
+ if code != 200:
+ raise RuntimeError(f"Tern returned {code} for shipment {shipment_id}: {body}")
+ return _TERN_STATUS.get(body.get("status"), PROBLEM)
def cancel(order: Order) -> bool: