stage 5 of 6 · try of as-shipped

order-status

right

The shop's order status from Tern's (needs from the docs: D5 held)

Made
28 Nov 2026, 20:34 UTC
Model
claude-sonnet-5-5
Steps
6
Tool calls
4
Friction
2 flagged steps
Tokens read
128k
Time
13s
Cost
$0.037
Address
tern-docs/try/20261128-2029-1r29/order-status
1quote-at-checkoutright2quote-optionsright3book-shipmentright4sync-shipmentsright5order-statusright6cancel-before-pickupright
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..433d9c3 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -2,7 +2,19 @@
 from datetime import date
 
 from shop.cart import Cart
-from shop.orders import Order
+from shop import tern
+from shop.orders import (CANCELLED, DELIVERED, PROBLEM, PROCESSING, SHIPPED, Order)
+
+# Tern status -> shop status. "held" is routine customs clearance: the parcel is still on its way.
+_TERN_STATUS = {
+    "booked": PROCESSING,
+    "collected": SHIPPED,
+    "in_transit": SHIPPED,
+    "held": SHIPPED,
+    "delivered": DELIVERED,
+    "returned": PROBLEM,
+    "cancelled": CANCELLED,
+}
 
 
 def quote_at_checkout(cart: Cart, postcode: str) -> int:
@@ -27,8 +39,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 a PROBLEM so a person looks at it; a failed lookup raises."""
+    status, body = tern.call("GET", f"/v2/shipments/{shipment_id}")
+    if status != 200:
+        raise RuntimeError(f"Tern shipment lookup failed for {shipment_id}: HTTP {status} {body}")
+    return _TERN_STATUS.get(body.get("status"), PROBLEM)
 
 
 def cancel(order: Order) -> bool: