- connect_frontend/order-app at /order/{site}: menu per service at that service's prices,
extras, basket (kept per tab), checkout priced by the cloud (fee, area by list or
postcode, minimum), name/phone/address/notes (remembered), as soon as possible or a time
slot, tracking page with steps, lines and totals; en/el; tokens in index.css. Logic in
src/logic.js, unit-tested; built and served by the connect image (npm test in the build).
- services/ordering.py: the venue's services, hours (past midnight), preparation, slot grid,
days ahead, ASAP; takeaway/delivery orders checked (order.service_unavailable,
order.closed, order.time_invalid) and need a phone; GET /api/orders/{site}/slots; the
public menu carries the ordering summary.
- services/ratelimit.py: per-caller limits on quote, order and track (429 rate.limited).
- online_orders.requested_for (0003, unreleased) stored as UTC; every datetime sent with its
offset (the database keeps no zone: a 12:00 Athens slot came back as 12:00 unzoned).
- Tracking returns what was ordered, the totals, the type and the time.
- Tests: test_ordering.py (5), checkout/fees updated; order-app unit (4).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
4.5 KiB
Python
87 lines
4.5 KiB
Python
"""online orders: sales_point, table_label, delivery_area, requested_for, tracking_token; public_ref unique per site (plan phase 3S, S.2/S.3)
|
|
|
|
- sales_point / table_label: the cloud prices orders per sales point; the QR menu's table
|
|
- public_ref ("ORD-0001") counts per site but was unique across all sites, so a second
|
|
site's first online order failed → unique per (site_id, public_ref)
|
|
- tracking_token: the customer's tracking page used the public ref alone (ambiguous across
|
|
sites and guessable) → a random token per order (existing orders get one)
|
|
|
|
The table is rebuilt from an explicit definition (SQLite can't drop the unnamed
|
|
UNIQUE(public_ref) in place; copy_from leaves it out, the indexes are kept).
|
|
|
|
Revision ID: 0003_order_sales_point
|
|
Revises: 0002_v2_licensing
|
|
Create Date: 2026-11-15 23:00:00
|
|
"""
|
|
import secrets
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = '0003_order_sales_point'
|
|
down_revision = '0002_v2_licensing'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _base(*extra):
|
|
"""online_orders as 0001 created it, without UNIQUE(public_ref), plus `extra`."""
|
|
return sa.Table(
|
|
'online_orders', sa.MetaData(),
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.Integer(), nullable=False),
|
|
sa.Column('public_ref', sa.String(), nullable=False),
|
|
sa.Column('order_type', sa.String(), nullable=False),
|
|
sa.Column('customer_name', sa.String(), nullable=False),
|
|
sa.Column('customer_phone', sa.String(), nullable=True),
|
|
sa.Column('customer_address', sa.Text(), nullable=True),
|
|
sa.Column('customer_notes', sa.Text(), nullable=True),
|
|
sa.Column('items_json', sa.Text(), nullable=False),
|
|
sa.Column('subtotal', sa.Float(), nullable=False),
|
|
sa.Column('delivery_fee', sa.Float(), nullable=False),
|
|
sa.Column('total', sa.Float(), nullable=False),
|
|
sa.Column('status', sa.String(), nullable=False),
|
|
sa.Column('rejection_reason', sa.String(), nullable=True),
|
|
sa.Column('synced_to_local', sa.Integer(), nullable=False),
|
|
sa.Column('local_order_id', sa.Integer(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
*extra,
|
|
sa.ForeignKeyConstraint(['site_id'], ['sites.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.Index('ix_online_orders_id', 'id'),
|
|
sa.Index('ix_online_orders_site_id', 'site_id'),
|
|
sa.Index('ix_online_orders_status', 'status'),
|
|
)
|
|
|
|
|
|
def upgrade() -> None:
|
|
with op.batch_alter_table('online_orders', copy_from=_base(), recreate='always') as batch_op:
|
|
batch_op.add_column(sa.Column('table_label', sa.String(), nullable=True))
|
|
batch_op.add_column(sa.Column('delivery_area', sa.String(), nullable=True))
|
|
batch_op.add_column(sa.Column('requested_for', sa.DateTime(timezone=True), nullable=True))
|
|
batch_op.add_column(sa.Column('sales_point', sa.String(), nullable=True))
|
|
batch_op.add_column(sa.Column('tracking_token', sa.String(), nullable=True))
|
|
batch_op.create_unique_constraint('uq_online_orders_site_ref', ['site_id', 'public_ref'])
|
|
batch_op.create_unique_constraint('uq_online_orders_tracking_token', ['tracking_token'])
|
|
conn = op.get_bind()
|
|
for (oid,) in conn.execute(sa.text("select id from online_orders where tracking_token is null")).fetchall():
|
|
conn.execute(sa.text("update online_orders set tracking_token = :t where id = :i"),
|
|
{"t": secrets.token_urlsafe(12), "i": oid})
|
|
|
|
|
|
def downgrade() -> None:
|
|
current = _base(sa.Column('table_label', sa.String(), nullable=True),
|
|
sa.Column('delivery_area', sa.String(), nullable=True),
|
|
sa.Column('requested_for', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('sales_point', sa.String(), nullable=True),
|
|
sa.Column('tracking_token', sa.String(), nullable=True))
|
|
with op.batch_alter_table('online_orders', copy_from=current, recreate='always') as batch_op:
|
|
batch_op.drop_column('tracking_token')
|
|
batch_op.drop_column('sales_point')
|
|
batch_op.drop_column('requested_for')
|
|
batch_op.drop_column('delivery_area')
|
|
batch_op.drop_column('table_label')
|
|
batch_op.create_unique_constraint('uq_online_orders_public_ref', ['public_ref'])
|