feat(backend): KDS item claims across screens; zone screens only touch their own items (platform-v2 3.2c)
- order_items.claimed_by / claimed_at (Alembic 0015). POST/DELETE
/api/kds/orders/{id}/items/{item}/claim (kds.bump): someone else's claim is refused
(kds.item_claimed), letting go works for anyone with kds.bump; live kds_item_claimed.
In progress claims for whoever did it; done/served/pending/declined clear the claim.
- Fix: order-level status and decline from a zone screen changed every zone's items;
now only the screen's zone, and a zone screen sees the order status of its own items.
- Terminal: "I'm on it" / "Let go" on the selected card, the cook's name on claimed items.
- Tests: backend +6, terminal unit +1, terminal.mjs +6 with a second screen and cook.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,7 +149,79 @@ def test_item_back_to_pending_reopens_the_order(client, screen, kitchen):
|
||||
"""Undo on the screen (3.2b): an item done → back to pending puts the order back too."""
|
||||
h, oid = screen["h"], kitchen["order"].id
|
||||
item = client.get("/api/kds/orders", headers=h).json()["orders"][0]["items"][0]["id"]
|
||||
for status, expected in (("done", "preparing"), ("pending", "pending")): # the Bar item is still to do
|
||||
for status, expected in (("done", "done"), ("pending", "pending")): # as far as this zone goes (3.2c)
|
||||
assert client.put(f"/api/kds/orders/{oid}/items/{item}/kds_status", headers=h, json={"status": status}).status_code == 200
|
||||
order = next(o for o in client.get("/api/kds/orders", headers=h).json()["orders"] if o["id"] == oid)
|
||||
assert order["kds_status"] == expected
|
||||
|
||||
|
||||
# ── claims (3.2c) ────────────────────────────────────────────────────────────
|
||||
|
||||
@pytest.fixture
|
||||
def second_screen(client, pair, make_user, kitchen):
|
||||
token, r = pair("kds", "Grill screen 2", config={"prep_zone_id": kitchen["grill"].id})
|
||||
chef = make_user(role="chef", nickname="Nikos")
|
||||
jwt = terminal_login(client, token, chef)
|
||||
return {"id": r.json()["id"], "h": {"X-Xenia-Device": token, "Authorization": f"Bearer {jwt}"}, "chef": chef}
|
||||
|
||||
|
||||
def steak(client, h, oid):
|
||||
order = next(o for o in client.get("/api/kds/orders", headers=h).json()["orders"] if o["id"] == oid)
|
||||
return order["items"][0]
|
||||
|
||||
|
||||
def test_two_screens_claim_without_stepping_on_each_other(client, screen, second_screen, kitchen): # "done when"
|
||||
oid = kitchen["order"].id
|
||||
item = steak(client, screen["h"], oid)["id"]
|
||||
url = f"/api/kds/orders/{oid}/items/{item}/claim"
|
||||
r = client.post(url, headers=second_screen["h"])
|
||||
assert r.status_code == 200 and r.json()["claimed_by_name"] == "Nikos"
|
||||
# the other screen sees it and can't take it
|
||||
assert steak(client, screen["h"], oid)["claimed_by_name"] == "Nikos"
|
||||
r = client.post(url, headers=screen["h"])
|
||||
assert r.status_code == 409 and r.json()["error"] == {"code": "kds.item_claimed", "params": {"name": "Nikos"}, "message": "Nikos is already on this item."}
|
||||
# claiming again is harmless; letting go works from any screen (a cook who left)
|
||||
assert client.post(url, headers=second_screen["h"]).status_code == 200
|
||||
assert client.delete(url, headers=screen["h"]).json()["claimed_by"] is None
|
||||
assert client.post(url, headers=screen["h"]).status_code == 200
|
||||
|
||||
|
||||
def test_in_progress_claims_and_bumping_clears(client, screen, second_screen, kitchen):
|
||||
oid = kitchen["order"].id
|
||||
item = steak(client, screen["h"], oid)["id"]
|
||||
status = f"/api/kds/orders/{oid}/items/{item}/kds_status"
|
||||
assert client.put(status, headers=second_screen["h"], json={"status": "preparing"}).status_code == 200
|
||||
assert steak(client, screen["h"], oid)["claimed_by_name"] == "Nikos"
|
||||
# in progress again from the other screen: still Nikos's
|
||||
client.put(status, headers=screen["h"], json={"status": "preparing"})
|
||||
assert steak(client, screen["h"], oid)["claimed_by_name"] == "Nikos"
|
||||
assert client.put(status, headers=screen["h"], json={"status": "done"}).status_code == 200
|
||||
assert steak(client, screen["h"], oid)["claimed_by"] is None
|
||||
|
||||
|
||||
def test_claims_need_kds_bump(client, pair, make_user, kitchen, screen):
|
||||
oid = kitchen["order"].id
|
||||
item = steak(client, screen["h"], oid)["id"]
|
||||
token, _ = pair("kds", "Pass", config={"prep_zone_id": kitchen["grill"].id})
|
||||
viewer = make_user(role="chef", remove=("kds.bump",))
|
||||
h = {"X-Xenia-Device": token, "Authorization": f"Bearer {terminal_login(client, token, viewer)}"}
|
||||
assert err(client.post(f"/api/kds/orders/{oid}/items/{item}/claim", headers=h)) == "access.denied"
|
||||
|
||||
|
||||
def test_order_actions_on_a_zone_screen_leave_other_zones_alone(client, screen, kitchen, owner_h):
|
||||
oid = kitchen["order"].id
|
||||
r = client.put(f"/api/kds/orders/{oid}/kds_status", headers=screen["h"], json={"status": "done"})
|
||||
assert r.status_code == 200 and r.json()["kds_status"] == "preparing" # the Bar's beer is still to do
|
||||
everything = next(o for o in client.get("/api/kds/orders", headers=owner_h).json()["orders"] if o["id"] == oid)
|
||||
assert {i["product_name"]: i["kds_status"] for i in everything["items"]} == {"Steak": "done", "Beer": "pending"}
|
||||
client.put(f"/api/kds/orders/{oid}/decline", headers=screen["h"], json={"decline_note": "x"})
|
||||
everything = next(o for o in client.get("/api/kds/orders", headers=owner_h).json()["orders"] if o["id"] == oid)
|
||||
assert {i["product_name"]: i["kds_status"] for i in everything["items"]} == {"Steak": "declined", "Beer": "pending"}
|
||||
|
||||
|
||||
def test_a_zone_screen_sees_how_far_its_own_items_are(client, screen, kitchen, owner_h):
|
||||
oid = kitchen["order"].id
|
||||
client.put(f"/api/kds/orders/{oid}/kds_status", headers=screen["h"], json={"status": "done"})
|
||||
mine = next(o for o in client.get("/api/kds/orders", headers=screen["h"]).json()["orders"] if o["id"] == oid)
|
||||
everything = next(o for o in client.get("/api/kds/orders", headers=owner_h).json()["orders"] if o["id"] == oid)
|
||||
assert (mine["kds_status"], everything["kds_status"]) == ("done", "preparing")
|
||||
|
||||
Reference in New Issue
Block a user