Fulfilment: mark packed orders as shipped + customer address edits

Python · Django · advanced · modification

Adds the ship step to fulfilment plus customer address editing. mark_shipped() validates the order is packed, books the parcel with the carrier, then stamps the order shipped with its tracking code and timestamp; PATCH /orders/<pk>/address/ lets customers correct the delivery address until the order ships (409 after that, 404 for signed-in non-owners). The carrier call is slow but the flow stays linear and easy to follow. Walked packed→shipped end-to-end on staging, tracking code lands on the order and the address endpoint rejects edits after shipment.

An e-commerce warehouse on Django 5 + DRF, Postgres, USE_TZ=True. Orders are packed at a station whose queue feeds the fulfilment worker; meanwhile customers can still correct their delivery address from the storefront.

Requirements

Files touched

--- orders/models.py
     )
     shipping_address = models.TextField()
+    tracking_code = models.CharField(max_length=64, blank=True, default="")
+    shipped_at = models.DateTimeField(null=True, blank=True)
     created_at = models.DateTimeField(auto_now_add=True)
 
--- orders/migrations/0006_order_tracking_code_and_more.py
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("orders", "0005_order_shipping_address"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="order",
+            name="tracking_code",
+            field=models.CharField(blank=True, default="", max_length=64),
+        ),
+        migrations.AddField(
+            model_name="order",
+            name="shipped_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+    ]
+

Review this PR

Python practice