feat(waiter): where each line came from; QR lines marked, the QR message opens the table (platform-v2 step 4.8b)

- order_items.source (Alembic 0025): waiter | counter | qr | online, set by the server
  (orders.add_priced_items: the phone / manager 'waiter', the counter 'counter'; the QR
  menu's lines 'qr', online orders 'online'; a split line keeps its source); lines of
  existing online orders backfilled 'online'; in the order's item output.
- Waiter: lines the guests sent from the QR menu (or an online order) carry a "📱 QR" /
  "🌐 Online" mark; the qr_order message's banner has "Open the table", and in the bell's
  list the message opens it.
- Tests: source per channel, migration 0025, QR placement marks 'qr'; waiter e2e +1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 09:59:57 +02:00
co-authored by Claude Opus 5.5
parent 198f8ff571
commit 1e8271e370
15 changed files with 124 additions and 9 deletions
@@ -66,3 +66,29 @@ def test_paid_lines_are_not_combined(client, db, menu, phone, floor):
assert client.post(f"/api/orders/{oid}/pay", headers=phone["h"], json={"item_ids": [first.id], "payment_method": "cash"}).status_code == 200
r = client.post(f"/api/orders/{oid}/items/combine", headers=phone["h"], json={"item_ids": [first.id, second.id]})
assert err(r) == "order.items_not_combinable" and r.json()["error"]["params"]["reason"] == "not_unpaid"
def test_lines_know_where_they_came_from(client, db, menu, phone, floor, till):
"""order_items.source (4.8): the phone's lines are 'waiter', the counter's 'counter' (QR: test_qr_table)."""
oid = order_with(client, phone, floor, [{"product_id": menu["coffee"].id, "quantity": 1}])
r = client.post(f"/api/pos/tables/{floor['t1'].id}/items", headers=till["h"], json={"lines": [{"product_id": menu["coffee"].id}]})
assert r.status_code == 201, r.text
assert [i.source for i in items(db, oid)] == ["waiter", "counter"]
assert [i["source"] for i in client.get(f"/api/orders/{oid}", headers=phone["h"]).json()["items"]] == ["waiter", "counter"]
def test_migration_0025_marks_online_lines(tmp_path):
from alembic import command
from sqlalchemy import create_engine, text
from core.schema import alembic_config, upgrade_to_head
eng = create_engine(f"sqlite:///{(tmp_path / 'm.db').as_posix()}")
with eng.begin() as conn:
command.upgrade(alembic_config(conn), "0024_role_permissions")
conn.execute(text("insert into orders (id, opened_by, status, source, order_type, kds_status) values (1, 1, 'open', 'online', 'delivery', 'pending'), (2, 1, 'open', 'pos', 'here', 'pending')"))
conn.execute(text("insert into order_items (id, order_id, product_id, added_by, quantity, unit_price, product_name, status, kds_status, printed, price_adjustment) "
"values (1, 1, 1, 1, 1, 3, 'x', 'active', 'pending', 0, 0), (2, 2, 1, 1, 1, 3, 'x', 'active', 'pending', 0, 0)"))
upgrade_to_head(eng)
with eng.connect() as conn:
rows = conn.execute(text("select id, source from order_items order by id")).fetchall()
eng.dispose()
assert rows == [(1, "online"), (2, None)]