feat(cloud): the cloud prices online orders itself; sites only touch their own data (platform-v2 3S, S.2)
- services/checkout.py: orders and quotes priced from the site's snapshot per sales point
(prices map; older snapshots: digital_price less discount); refused: unavailable or
not sold there, bad quantity/option/type, empty, order.price_changed when the browser's
unit price or total differs. Nothing the browser says about money is stored.
- POST /api/orders/{site}/quote; delivery needs phone + address.
- Fixes: pending orders, menu sync and stats snapshot acted on the site_id given, not the
authenticated site (a site could read another's orders or overwrite its menu/stats).
- Order refs are unique per site (a second site's first order failed); tracking by a
random token GET /api/orders/track/{token}; old /status/{ref} only while unambiguous.
- Alembic 0003: online_orders sales_point, table_label, tracking_token; table rebuilt.
- menu-app: tracking link uses the token, shows the order number; tells the customer when
the menu changed or the order failed.
- Tests: test_checkout.py (6), 0003 data migration.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,3 +89,33 @@ def test_nothing_calls_create_all():
|
||||
if not p.relative_to(root).as_posix().startswith(("tests/", "migrations/"))
|
||||
and re.search(r"\.create_all\(", p.read_text(encoding="utf-8", errors="ignore"))]
|
||||
assert bad == []
|
||||
|
||||
|
||||
def test_0003_keeps_orders_gives_tokens_and_refs_per_site(tmp_path):
|
||||
"""Existing online orders survive the table rebuild, get a tracking token, and two sites
|
||||
may now both have ORD-0001 (plan phase 3S, S.2)."""
|
||||
from schema import alembic_config
|
||||
from alembic import command
|
||||
import sqlalchemy as sa
|
||||
eng = create_engine(f"sqlite:///{(tmp_path / 'c.db').as_posix()}")
|
||||
with eng.begin() as conn:
|
||||
command.upgrade(alembic_config(conn), "0002_v2_licensing")
|
||||
for sid in (1, 2):
|
||||
conn.execute(text("insert into sites (id, site_id, name, owner_name, contact_email, secret_key_hash, is_active, "
|
||||
"license_expires_at, created_at, order_counter, menu_mode) "
|
||||
"values (:i, :s, 'S', 'O', 'o@x', 'x', 1, '2027-01-01', '2026-01-01', 1, 'order')"), {"i": sid, "s": f"site-{sid}"})
|
||||
conn.execute(text("insert into online_orders (site_id, public_ref, order_type, customer_name, items_json, subtotal, "
|
||||
"delivery_fee, total, status, synced_to_local) values (1, 'ORD-0001', 'dine_in', 'A', '[]', 1, 0, 1, 'delivered', 1)"))
|
||||
upgrade_to_head(eng)
|
||||
with eng.begin() as conn:
|
||||
row = conn.execute(text("select public_ref, tracking_token from online_orders")).one()
|
||||
assert row[0] == "ORD-0001" and row[1]
|
||||
conn.execute(text("insert into online_orders (site_id, public_ref, order_type, customer_name, items_json, subtotal, "
|
||||
"delivery_fee, total, status, synced_to_local) values (2, 'ORD-0001', 'dine_in', 'B', '[]', 1, 0, 1, 'delivered', 0)"))
|
||||
with pytest.raises(sa.exc.IntegrityError):
|
||||
with conn.begin_nested():
|
||||
conn.execute(text("insert into online_orders (site_id, public_ref, order_type, customer_name, items_json, subtotal, "
|
||||
"delivery_fee, total, status, synced_to_local) values (2, 'ORD-0001', 'dine_in', 'C', '[]', 1, 0, 1, 'delivered', 0)"))
|
||||
idx = {i["name"] for i in sa.inspect(conn).get_indexes("online_orders")}
|
||||
eng.dispose()
|
||||
assert {"ix_online_orders_site_id", "ix_online_orders_status"} <= idx
|
||||
|
||||
Reference in New Issue
Block a user