feat(cloud): online orders keep the delivery area's id for the site's fee check

The site checks the cloud's delivery fee with its own engine when it pulls an order (plan
phase 3S, step S.5) and needs the area by id: a name can change between a menu push and
the order. New column online_orders.delivery_area_id (migration 0004), set from the priced
cart, and in the pending-orders payload (C-4, additive).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 15:38:00 +02:00
co-authored by Claude Opus 5.5
parent b25bfcda3e
commit 9ccb47cfd1
5 changed files with 31 additions and 1 deletions
@@ -0,0 +1,27 @@
"""online orders: delivery_area_id (plan phase 3S, S.5)
The site checks the cloud's delivery fee with its own engine when it pulls an order, and
needs the area by id (a name can change between a menu push and the order).
Revision ID: 0004_order_area_id
Revises: 0003_order_sales_point
Create Date: 2026-11-16 18:00:00
"""
from alembic import op
import sqlalchemy as sa
revision = '0004_order_area_id'
down_revision = '0003_order_sales_point'
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table('online_orders', schema=None) as batch_op:
batch_op.add_column(sa.Column('delivery_area_id', sa.Integer(), nullable=True))
def downgrade() -> None:
with op.batch_alter_table('online_orders', schema=None) as batch_op:
batch_op.drop_column('delivery_area_id')
+1
View File
@@ -26,6 +26,7 @@ class OnlineOrder(Base):
customer_notes = Column(Text, nullable=True) customer_notes = Column(Text, nullable=True)
table_label = Column(String, nullable=True) # the QR menu's table, as the customer gave it table_label = Column(String, nullable=True) # the QR menu's table, as the customer gave it
delivery_area = Column(String, nullable=True) # the delivery area's name (S.3) delivery_area = Column(String, nullable=True) # the delivery area's name (S.3)
delivery_area_id = Column(Integer, nullable=True) # the site's area id (S.5: the site checks the fee)
requested_for = Column(DateTime(timezone=True), nullable=True) # the time slot picked (S.4); null = asap requested_for = Column(DateTime(timezone=True), nullable=True) # the time slot picked (S.4); null = asap
sales_point = Column(String, nullable=True) # the site's sales point (phase 3S, S.2) sales_point = Column(String, nullable=True) # the site's sales point (phase 3S, S.2)
+1
View File
@@ -122,6 +122,7 @@ def create_order(site_slug: str, body: OnlineOrderCreate, request: Request, db:
customer_notes=body.customer_notes, customer_notes=body.customer_notes,
table_label=(body.customer_table or "").strip() or None, table_label=(body.customer_table or "").strip() or None,
delivery_area=priced.area_name, delivery_area=priced.area_name,
delivery_area_id=priced.area_id,
# stored as UTC: SQLite keeps no time zone (read back naive = UTC, schemas mark it) # stored as UTC: SQLite keeps no time zone (read back naive = UTC, schemas mark it)
requested_for=(body.requested_for.astimezone(timezone.utc).replace(tzinfo=None) requested_for=(body.requested_for.astimezone(timezone.utc).replace(tzinfo=None)
if body.order_type in ("takeaway", "delivery") and body.requested_for else None), if body.order_type in ("takeaway", "delivery") and body.requested_for else None),
+1
View File
@@ -83,6 +83,7 @@ class PendingOrderOut(BaseModel):
customer_notes: Optional[str] = None customer_notes: Optional[str] = None
table_label: Optional[str] = None # the QR menu's table (S.2) table_label: Optional[str] = None # the QR menu's table (S.2)
delivery_area: Optional[str] = None # the delivery area's name (S.3) delivery_area: Optional[str] = None # the delivery area's name (S.3)
delivery_area_id: Optional[int] = None # the site's area id (S.5)
requested_for: Optional[datetime] = None # when the customer wants it (S.4); None = as soon as possible requested_for: Optional[datetime] = None # when the customer wants it (S.4); None = as soon as possible
sales_point: Optional[str] = None # the site's sales point (S.2) sales_point: Optional[str] = None # the site's sales point (S.2)
items_json: str items_json: str
+1 -1
View File
@@ -57,7 +57,7 @@ def test_the_cloud_charges_the_venues_fee(client, admin_h):
ok = _order(client, site, "delivery", customer_address="Main sq. 3", area_id=1, total=7.6) ok = _order(client, site, "delivery", customer_address="Main sq. 3", area_id=1, total=7.6)
assert ok.status_code == 201, ok.text assert ok.status_code == 201, ok.text
stored = next(o for o in client.get(f"/api/orders/pending/{numeric}", headers=_h(site)).json() if o["public_ref"] == ok.json()["public_ref"]) stored = next(o for o in client.get(f"/api/orders/pending/{numeric}", headers=_h(site)).json() if o["public_ref"] == ok.json()["public_ref"])
assert (stored["delivery_fee"], stored["total"], stored["delivery_area"]) == (2.0, 7.6, "Centre") assert (stored["delivery_fee"], stored["total"], stored["delivery_area"], stored["delivery_area_id"]) == (2.0, 7.6, "Centre", 1)
# takeaway: the delivery rules don't apply # takeaway: the delivery rules don't apply
assert client.post(f"/api/orders/{site['site_id']}/quote", json={"order_type": "takeaway", "items": [{"product_id": COLA, "quantity": 1}]}).json()["delivery_fee"] == 0 assert client.post(f"/api/orders/{site['site_id']}/quote", json={"order_type": "takeaway", "items": [{"product_id": COLA, "quantity": 1}]}).json()["delivery_fee"] == 0