Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 49 minutes ago History
kitchen_ticket.py · 7.9 KB · 213 lines
1"""site_kitchen_ticket -- one order, printed for the person making it.
2GET /kitchen/{order_id}/ticket.
3
4NO PRICES. Not "prices in small type", not "prices unless somebody ticks
5something": none, ever, for the same reason site_packing_slip carries
6none. A ticket is not an invoice. It exists so the cook can make the
7right thing, and what it cost is a conversation that already happened
8with somebody else -- usually a card reader, sometimes a different person
9entirely. A cook who can see the money on every ticket is being handed
10information they cannot act on, on the one piece of paper that has to be
11readable in three seconds with their hands full.
12
13**The lines and their notes, and almost nothing else.** The packing slip
14already prints `customer_note` -- what the shopper needs the PACKER to
15know. This prints `line_note`, per line, which is where a cook actually
16reads it: "no onions" under the burger it is true of, not in a paragraph
17at the bottom of the order that has to be matched back up by hand.
18`customer_note` is printed too, once, at the top, because "I am
19allergic" is addressed to whoever is making the food and it is worth
20having on the paper in the kitchen rather than only on the one in
21dispatch.
22
23Printable rather than pretty, and BIG: minimal print CSS, nav hidden at
24@media print, and type sized for a metre away. Operator-facing, behind
25the ordinary registered permission like the packing slip and for the same
26reason -- the order id is an internal record id, so a public page here
27would enumerate every order in the shop.
28
29The promised time is on it. A ticket that says what to make and not when
30it is due is a ticket that gets done in the order the pile happens to sit
31in, which is exactly the failure the queue page exists to prevent.
32
33An unknown order is a friendly 404 in the same shell, never a traceback:
34a mistyped link is somebody who is still standing in a kitchen trying to
35make food.
36
37**The page is the only gate in front of the order**, because it reads
38storage directly, so it asks the permission engine the question the orders
39API would (object_access): an order the caller may not read through
40/collections/orders is "not found" here too -- the same page as a mistyped
41id, so a guessed id learns nothing. The registered execute rule alone let
42any signed-in user print any order's customer, note and lines
43(bug-reports/2026-11-28-06-14-28).
44"""
45
46import html
47import os
48from datetime import datetime
49
50import object_access
51import object_records
52
53ACTOR = "site_kitchen_ticket"
54
55
56def _base_dir():
57 return os.environ.get("DBBASIC_DATA_DIR", "data")
58
59
60def _text(value):
61 return str(value if value is not None else "").strip()
62
63
64def _esc(value):
65 return html.escape(_text(value))
66
67
68def _esc_multiline(value):
69 return _esc(value).replace("\n", "<br>")
70
71
72def _parse_when(value):
73 """Same reading as site_kitchen's and system_pickup_attention's: ISO
74 in, NAIVE LOCAL wall-clock out, None when it will not parse.
75 Duplicated rather than shared because objects on this platform are
76 executed, not imported, and ten lines is not worth a module boundary
77 (docs/logic-decisions.md #4)."""
78 raw = _text(value)
79 if not raw:
80 return None
81 try:
82 when = datetime.fromisoformat(raw.replace("Z", "+00:00"))
83 except ValueError:
84 return None
85 if when.tzinfo is not None:
86 when = when.astimezone().replace(tzinfo=None)
87 return when
88
89
90_STYLE = """
91.wrap { max-width: 640px; margin: 0 auto; padding: 2rem 1.25rem; }
92.pagehead { margin-bottom: 1rem; }
93.pagehead h1 { margin: 0 0 0.25rem; font-size: 1.6rem; }
94.promised { font-size: 2.4rem; font-weight: 700; line-height: 1.1; margin: 0.2rem 0; }
95.who { font-size: 1.3rem; font-weight: 600; }
96.hint { color: var(--muted, #999); font-size: 0.9rem; }
97.note { border: 1px solid var(--line, #333); border-radius: 8px; padding: 0.8rem 1rem; margin: 1rem 0; white-space: pre-wrap; font-size: 1.1rem; }
98ul.klines { list-style: none; margin: 1.2rem 0; padding: 0; font-size: 1.35rem; }
99ul.klines li { padding: 0.5rem 0; border-top: 2px solid var(--line, #38384a); }
100ul.klines .qty { font-weight: 700; display: inline-block; min-width: 2.6rem; }
101ul.klines .line-note { display: block; margin-left: 2.6rem; font-style: italic; font-weight: 600; font-size: 1.15rem; }
102.notfound { text-align: center; padding: 3rem 1rem; }
103@media print {
104 nav, header.app, .noprint, .btn { display: none !important; }
105 .wrap { max-width: none; padding: 0; }
106 body { background: #fff; color: #000; }
107 .note { border-color: #999; }
108}
109"""
110
111
112def _page(body, *, title, status=200):
113 page = {
114 "content_type": "text/html; charset=utf-8",
115 "body": f"""<!doctype html>
116<html lang="en">
117<head>
118<meta charset="utf-8">
119<meta name="viewport" content="width=device-width, initial-scale=1">
120<title>{_esc(title)}</title>
121<link rel="stylesheet" href="/style">
122<style>{_STYLE}</style>
123</head>
124<body>
125<div class="wrap">
126{body}
127</div>
128<script src="/nav"></script>
129</body>
130</html>""",
131 }
132 if status != 200:
133 page["status"] = status
134 return page
135
136
137def _not_found():
138 return _page(
139 '<div class="notfound"><h1>Not found</h1>'
140 '<p class="hint">There is no order with that id. It may have been '
141 'mistyped, or the order may have been deleted. '
142 '<a href="/kitchen">Back to the kitchen</a>.</p></div>',
143 title="Kitchen ticket -- not found", status=404)
144
145
146def _lines_html(lines):
147 if not lines:
148 return ('<p class="hint">This order has no lines -- there is nothing '
149 'on it to make.</p>')
150 items = []
151 for line in lines:
152 quantity = _text(line.get("quantity")) or "1"
153 description = (_text(line.get("description"))
154 or _text(line.get("product_id")) or "Item")
155 note = _text(line.get("line_note"))
156 note_html = (f'<span class="line-note">{_esc(note)}</span>'
157 if note else "")
158 items.append(f'<li><span class="qty">{_esc(quantity)}&times;</span>'
159 f'{_esc(description)}{note_html}</li>')
160 return f'<ul class="klines">{"".join(items)}</ul>'
161
162
163def GET(request):
164 base = _base_dir()
165 order_id = _text(request.get("order_id"))
166 if not order_id:
167 return _not_found()
168
169 access = object_access.Access(request.get("_identity"), base_dir=base)
170 try:
171 order = access.get("orders", order_id)
172 except Exception:
173 return _not_found()
174 if not order:
175 return _not_found()
176
177 # The order is the unit of access: its lines are part of it, and a
178 # ticket missing a line is a dish nobody makes.
179 try:
180 # access: lines of the order read through Access above
181 lines = [row for row in object_records.read_collection_records(
182 "order_lines", base_dir=base)
183 if _text(row.get("order_id")) == order_id]
184 except Exception:
185 lines = []
186 lines.sort(key=lambda row: _text(row.get("description")))
187
188 number = _text(order.get("number")) or order_id
189 who = _text(order.get("customer_name")) or "No name on this order"
190 when = _parse_when(order.get("promised_at"))
191 promised = (f'<div class="promised">{when.strftime("%H:%M")}</div>'
192 if when is not None
193 else '<p class="hint">No promised time on this order.</p>')
194
195 note = _text(order.get("customer_note"))
196 note_html = ('<div class="note"><strong>For the kitchen</strong><br>'
197 f'{_esc_multiline(note)}</div>' if note else "")
198
199 body = f"""
200<div class="pagehead">
201<h1>Kitchen ticket</h1>
202<p class="hint">Order {_esc(number)}</p>
203{promised}
204<div class="who">{_esc(who)}</div>
205</div>
206{note_html}
207{_lines_html(lines)}
208<p class="hint">This is a kitchen ticket, not an invoice: it says what to
209make and deliberately carries no prices -- the money conversation happened
210somewhere else, with somebody who may not be the person cooking.</p>
211<p class="hint noprint"><a href="/kitchen">Kitchen queue</a></p>
212"""
213 return _page(body, title=f"Kitchen ticket -- order {number}")