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..9d28a8c 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -2,8 +2,20 @@
from datetime import date
from shop.cart import Cart
+from shop import orders, tern
from shop.orders import Order
+# Tern shipment status -> the shop's status. "held" is normal customs clearance: still on its way.
+_STATUS_MAP = {
+ "booked": orders.PROCESSING,
+ "collected": orders.SHIPPED,
+ "in_transit": orders.SHIPPED,
+ "held": orders.SHIPPED,
+ "delivered": orders.DELIVERED,
+ "returned": orders.PROBLEM,
+ "cancelled": orders.CANCELLED,
+}
+
def quote_at_checkout(cart: Cart, postcode: str) -> int:
"""The cheapest price Tern offers to ship this cart from the warehouse to postcode, in pence."""
@@ -28,7 +40,11 @@ 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
+ status, body = tern.call("GET", f"/v2/shipments/{shipment_id}")
+ if status != 200:
+ raise RuntimeError(f"Tern returned {status} for shipment {shipment_id}: {body}")
+ # A status we don't recognise needs a person to look at it.
+ return _STATUS_MAP.get(body.get("status"), orders.PROBLEM)
def cancel(order: Order) -> bool: