- Scenes (Alembic 0043, models/scene.py, /api/scenes, core.scenes.manage): named modes on or off (optionally until a time); price rules / deals get the condition "a scene is on"; signage lines can play only during a scene; turning one on tells every screen and pushes the online menu. - Signage schedules are lines (signage_schedule_items): playlist, screens ([] = every screen), priority, days, smart days (1st / last day, first / last week, Greek public holidays or not: core/calendar_days.py, mirrored in @xenia/signage), hours, dates, scene. No line → the screen's default playlist. 0043 turns the old named schedules into lines for their screens. - Screens: default playlist, TV shape, turn; what plays now and why. - Manager: tabs Screens · Playlists · Schedules · Slides (placeholder) · Message and weather; schedule lines with playlist / screens / priority / delete on one line; the playlist editor's horizontal timeline of fixed cards, the slide's basics beside its preview (one height), then its content; Management → Scenes; the scene condition in pricing. - Tests: backend (lines, smart days, scenes, prices), player logic, e2e. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
3.2 KiB
Python
52 lines
3.2 KiB
Python
"""Scenes (owner 2026-11-21): named modes of the venue (party mode) that are on or off; price
|
|
rules follow them ("a scene is on"), signage lines too (tests/test_signage_schedule.py)."""
|
|
from datetime import timedelta
|
|
|
|
from core.timeutil import utcnow
|
|
from tests.test_live import err, owner_h, pair, terminal_login # noqa: F401 (fixtures)
|
|
from tests.test_pos import menu, till # noqa: F401 (fixtures)
|
|
from tests.test_pricing_setup import happy_hour
|
|
|
|
|
|
def test_scenes_are_made_and_switched(client, owner_h, make_user, login):
|
|
r = client.post("/api/scenes", headers=owner_h, json={"name": " Party mode ", "color": "#ff6699"})
|
|
assert r.status_code == 201 and r.json()["name"] == "Party mode" and r.json()["active"] is False
|
|
sid = r.json()["id"]
|
|
assert client.put(f"/api/scenes/{sid}/active", headers=owner_h, json={"active": True}).json()["active"] is True
|
|
soon = (utcnow() + timedelta(hours=2)).isoformat()
|
|
on = client.put(f"/api/scenes/{sid}/active", headers=owner_h, json={"active": True, "until": soon}).json()
|
|
assert on["active"] is True and on["until"]
|
|
past = (utcnow() - timedelta(minutes=1)).isoformat()
|
|
assert err(client.put(f"/api/scenes/{sid}/active", headers=owner_h, json={"active": True, "until": past})) == "scene.until_past"
|
|
assert err(client.put("/api/scenes/99999/active", headers=owner_h, json={"active": True})) == "scene.not_found"
|
|
assert client.post("/api/scenes", headers=owner_h, json={"name": "x", "color": "pink"}).status_code == 422
|
|
# a waiter can't switch scenes
|
|
h = login(make_user(role="waiter"), client="waiter")
|
|
assert client.put(f"/api/scenes/{sid}/active", headers=h, json={"active": False}).status_code == 403
|
|
|
|
|
|
def test_a_scene_turns_itself_off(db, client, owner_h):
|
|
from models.scene import Scene
|
|
from services.scenes import active_ids
|
|
s = Scene(name="Brunch", is_active=True, until=utcnow() - timedelta(seconds=1), sort_order=0)
|
|
db.add(s)
|
|
db.commit()
|
|
assert s.id not in active_ids(db)
|
|
assert client.get("/api/scenes", headers=owner_h).json()[0]["active"] is False
|
|
|
|
|
|
def test_a_price_rule_follows_a_scene(client, owner_h, till, menu):
|
|
line = {"product_id": menu["coffee"].id, "quantity": 2}
|
|
sid = client.post("/api/scenes", headers=owner_h, json={"name": "Party mode"}).json()["id"]
|
|
rule = happy_hour(targets=[{"target_type": "item", "target_ids": [menu["coffee"].id]}])
|
|
rule["conditions"] = [{"condition_type": "scene_active", "params": {"scene_id": sid}}]
|
|
r = client.post("/api/pricing/modifiers", headers=owner_h, json=rule)
|
|
assert r.status_code == 201, r.text
|
|
assert client.post("/api/pos/quote", headers=till["h"], json={"lines": [line]}).json()["total"] == 6.0
|
|
client.put(f"/api/scenes/{sid}/active", headers=owner_h, json={"active": True})
|
|
assert client.post("/api/pos/quote", headers=till["h"], json={"lines": [line]}).json()["total"] == 4.8
|
|
client.put(f"/api/scenes/{sid}/active", headers=owner_h, json={"active": False})
|
|
assert client.post("/api/pos/quote", headers=till["h"], json={"lines": [line]}).json()["total"] == 6.0
|
|
bad = dict(rule, conditions=[{"condition_type": "scene_active", "params": {}}])
|
|
assert err(client.post("/api/pricing/modifiers", headers=owner_h, json=bad)) == "pricing.bad_condition"
|