Files
xenia-pos-cloud/cloud_backend/schemas/online_order.py
T
bonaminandClaude Opus 5.5 d5b8492512 feat: delivery areas drawn on a map: the customer pins the address (plan 6R.G)
- services/fees.py: the site's engine (shapes matched by the pin), shared cases
- checkout: price_cart(pin=), delivery_areas with kind (+ geometry for shapes),
  venue_point in the public menu (postcodes and rules stay on the cloud)
- orders: quote / create take lat / lng; online_orders.lat / lng (Alembic 0007),
  sent to the site with the pending orders
- order app: PinMap (Leaflet + OpenStreetMap tiles), 'Pin it on the map' first
  when the venue drew areas, the browser's location offered; lat / lng sent
- tests: cloud test_fees (pinned quote and order), order-app logic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:56:13 +02:00

121 lines
4.7 KiB
Python

from __future__ import annotations
from datetime import datetime
from typing import Optional
from datetime import timezone
from pydantic import BaseModel, Field, field_serializer
def _utc(value):
"""The cloud's database keeps no time zone: a naive datetime is UTC. Sent with its offset."""
if value is None:
return None
return (value.replace(tzinfo=timezone.utc) if value.tzinfo is None else value).isoformat()
class OrderItemIn(BaseModel):
"""What the customer wants. Prices come from the venue's menu (services/checkout.py);
name and unit_price, if sent, are only compared (phase 3S, S.2)."""
product_id: int
quantity: int
name: Optional[str] = None
unit_price: Optional[float] = None
options: list = [] # quick option ids (or {id})
class QuoteRequest(BaseModel):
order_type: str # dine_in | takeaway | delivery | preorder
items: list[OrderItemIn] = Field(max_length=100)
area_id: Optional[int] = None # the delivery area picked (S.3)
postcode: Optional[str] = Field(default=None, max_length=20)
lat: Optional[float] = Field(default=None, ge=-90, le=90) # 6R.G: the customer's pin on the map
lng: Optional[float] = Field(default=None, ge=-180, le=180)
class OnlineOrderCreate(BaseModel):
order_type: str # dine_in | takeaway | delivery | reservation | preorder
customer_name: str = Field(min_length=1, max_length=100)
party_size: Optional[int] = None # reservations (S.6)
customer_phone: Optional[str] = Field(default=None, max_length=40)
customer_address: Optional[str] = Field(default=None, max_length=500)
customer_notes: Optional[str] = Field(default=None, max_length=1000)
customer_table: Optional[str] = Field(default=None, max_length=40) # ignored since S.7 (the token says)
table_token: Optional[str] = Field(default=None, max_length=100) # the table's QR token (S.7)
area_id: Optional[int] = None # the delivery area picked (S.3)
postcode: Optional[str] = Field(default=None, max_length=20)
lat: Optional[float] = Field(default=None, ge=-90, le=90) # 6R.G: the customer's pin on the map
lng: Optional[float] = Field(default=None, ge=-180, le=180)
requested_for: Optional[datetime] = None # a time slot (S.4); None = as soon as possible
items: list[OrderItemIn] = Field(default_factory=list, max_length=100)
# what the customer was shown: compared, never stored as sent
subtotal: Optional[float] = None
delivery_fee: Optional[float] = None
total: Optional[float] = None
class OnlineOrderCreated(BaseModel):
order_id: int
public_ref: str
status: str
tracking_token: Optional[str] = None # the tracking page: GET /api/orders/track/{token} (S.2)
total: Optional[float] = None
class OrderStatusOut(BaseModel):
public_ref: str
status: str
rejection_reason: Optional[str] = None
# S.4: what the tracking page shows (all optional: older clients ignore them)
order_type: Optional[str] = None
requested_for: Optional[datetime] = None
party_size: Optional[int] = None # reservations (S.6)
created_at: Optional[datetime] = None
lines: Optional[list] = None
subtotal: Optional[float] = None
delivery_fee: Optional[float] = None
total: Optional[float] = None
@field_serializer('requested_for', 'created_at')
def _times(self, value):
return _utc(value)
class PendingOrderOut(BaseModel):
id: int
public_ref: str
order_type: str
customer_name: str
customer_phone: Optional[str] = None
customer_address: Optional[str] = None
customer_notes: Optional[str] = None
table_label: Optional[str] = None # the QR menu's table (S.2)
table_id: Optional[int] = None # the site's table, from a valid QR token (S.7)
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)
lat: Optional[float] = None # 6R.G: the customer's pin
lng: Optional[float] = None
requested_for: Optional[datetime] = None # when the customer wants it (S.4); None = as soon as possible
party_size: Optional[int] = None # reservations (S.6)
sales_point: Optional[str] = None # the site's sales point (S.2)
items_json: str
subtotal: float
delivery_fee: float
total: float
status: str
created_at: datetime
model_config = {"from_attributes": True}
@field_serializer('requested_for', 'created_at')
def _times(self, value):
return _utc(value)
class OrderSyncedRequest(BaseModel):
local_order_id: int
class OrderStatusUpdateRequest(BaseModel):
status: str
rejection_reason: Optional[str] = None