feat(connect): the site side of online orders: fee line, customer's time, price check

Plan phase 3S, step S.5.
- Pull: an online order keeps the customer's time (orders.requested_for, None = as soon as
  possible) and delivery area; quick options are stored in the site's entry shape; items get
  their cost snapshot.
- The delivery fee is its own order line: a system product (products.system_key
  "delivery_fee", lifecycle "system", sold nowhere; services/system_products.py), created on
  first use in the venue's language with the VAT group most products use. Added printed and
  served, so kitchen tickets and the KDS never see it; paid at the counter with the items,
  counted in the shift, on the fiscal receipt with its VAT group. Never listed in the
  catalogue (products list, export, edit endpoints → 404) and never added by hand.
- Price check (services/online_check.py): each line priced as the snapshot prices it, at the
  order's time, and the fee through the same engine with the site's rules and the cloud's
  area id; differences kept on orders.online_price_diff and shown. The customer pays what
  the cloud charged.
- Counter: time chip (or as soon as possible), area, fee line, price warning; takeaway is
  its own kind (was shown as "at the venue") and finishes as "collected". KDS cards show the
  online reference and the time; kitchen tickets print the reference, the type and the time.
- Manager: Online ordering → "The fee on the receipt" (name, VAT group;
  PUT /api/connect/fees/fee-product, fees.vat_group_unknown); the online orders page shows
  the time, area and price warning.
- Migration 0019. Tests: tests/test_online_site_side.py (6), terminal unit test, e2e
  (terminal: fee, time, warning, paid in full; manager: fee line settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 15:38:25 +02:00
co-authored by Claude Opus 5.5
parent 8ea44d71aa
commit 0ca700279a
38 changed files with 899 additions and 69 deletions
+47 -5
View File
@@ -66,6 +66,34 @@ def _cap(text: str, caps: bool) -> str:
return text.upper() if caps else text
def _online_meta(order) -> list[tuple[str, str]]:
"""An online order's ticket lines (phase 3S, S.5): [(label, value)] - its reference and
type, and when the customer wants it (venue time; the date only when it isn't today)."""
if getattr(order, "source", None) != "online":
return []
from core.timeutil import to_venue, venue_now
kind = order.online_order_type or order.order_type
label = _tr("print.ticket.type." + kind) if kind in ("delivery", "takeaway", "dine_in", "preorder") else kind
out = [(_tr("print.ticket.online_label"), f"{order.online_order_ref or order.id} - {label}")]
if kind in ("delivery", "takeaway", "preorder"):
when = to_venue(order.requested_for) if order.requested_for else None
if when is None:
value = _tr("print.ticket.asap")
elif when.date() == venue_now().date():
value = when.strftime("%H:%M")
else:
value = when.strftime("%d/%m %H:%M")
out.append((_tr("print.ticket.for_label"), value))
return out
def _place(order, table_name: str) -> str:
"""What the compact header shows as the table: the online reference for online orders."""
if getattr(order, "source", None) == "online" and order.table is None:
return order.online_order_ref or str(order.id)
return table_name
def _gr(text: str) -> bytes:
"""Encode text to CP737 bytes. Replaces unknown chars instead of crashing."""
return text.encode('cp737', errors='replace')
@@ -641,9 +669,11 @@ def _print_kitchen_ticket_body(p: Network, order: Order, items: List[OrderItem],
if compact:
p._raw(b'\x1b\x61\x00')
_apply_font(p, sz_ord, b_ord)
header = _tr("print.ticket.compact_header", order=order.id, table=table_name, time=now_str, waiter=waiter_nick)
header = _tr("print.ticket.compact_header", order=order.id, table=_place(order, table_name), time=now_str, waiter=waiter_nick)
if customer_count:
header += _tr("print.ticket.compact_guests", count=customer_count)
for label, value in _online_meta(order)[1:]:
header += f" | {label} {value}"
_raw_text(p, (header.upper() if c_ord else header) + "\n")
_reset_font(p)
_divider(p, div, line_width)
@@ -655,7 +685,12 @@ def _print_kitchen_ticket_body(p: Network, order: Order, items: List[OrderItem],
_divider(p, div, line_width)
p._raw(b'\x1b\x61\x00')
_apply_font(p, sz_meta, b_meta)
_raw_text(p, _cap(_tr("print.ticket.table_label"), c_meta) + " " + _tr("print.ticket.table_value", table=table_name) + "\n")
online = _online_meta(order)
if online and order.table is None:
for label, value in online:
_raw_text(p, _cap(label, c_meta) + f" {value}\n")
else:
_raw_text(p, _cap(_tr("print.ticket.table_label"), c_meta) + " " + _tr("print.ticket.table_value", table=table_name) + "\n")
_raw_text(p, _cap(_tr("print.ticket.date_label"), c_meta) + f" {now_str}\n")
_raw_text(p, _cap(_tr("print.ticket.waiter_label"), c_meta) + f" {waiter_nick}\n")
if customer_count:
@@ -1445,7 +1480,7 @@ def _do_print_cancellation(order_id: int, item_ids: List[int], db: Session):
def _print_cancel_ticket(p: Network, order: Order, items: List[OrderItem], db: Session, line_width: int, div: str):
cfg = _load_print_settings(db)
table_name = order.table.label or str(order.table.number) if order.table else str(order.table_id)
table_name = _place(order, order.table.label or str(order.table.number) if order.table else str(order.table_id))
now_str = _greek_date(utcnow())
def _cancel_banner():
@@ -2076,9 +2111,11 @@ def print_service_items_sync(order: Order, service_entries: List[dict], db: Sess
if compact:
p._raw(b'\x1b\x61\x00')
_apply_font(p, sz_ord, b_ord)
header = _tr("print.ticket.compact_header", order=order.id, table=table_name, time=now_str, waiter=waiter_nick)
header = _tr("print.ticket.compact_header", order=order.id, table=_place(order, table_name), time=now_str, waiter=waiter_nick)
if customer_count:
header += _tr("print.ticket.compact_guests", count=customer_count)
for label, value in _online_meta(order)[1:]:
header += f" | {label} {value}"
_raw_text(p, (header.upper() if c_ord else header) + "\n")
_reset_font(p)
_divider(p, div, pr.line_width or LINE_WIDTH)
@@ -2087,7 +2124,12 @@ def print_service_items_sync(order: Order, service_entries: List[dict], db: Sess
_divider(p, div, pr.line_width or LINE_WIDTH)
p._raw(b'\x1b\x61\x00')
_apply_font(p, sz_meta, b_meta)
_raw_text(p, _cap(_tr("print.ticket.table_label"), c_meta) + " " + _tr("print.ticket.table_value", table=table_name) + "\n")
online = _online_meta(order)
if online and order.table is None:
for label, value in online:
_raw_text(p, _cap(label, c_meta) + f" {value}\n")
else:
_raw_text(p, _cap(_tr("print.ticket.table_label"), c_meta) + " " + _tr("print.ticket.table_value", table=table_name) + "\n")
_raw_text(p, _cap(_tr("print.ticket.date_label"), c_meta) + f" {now_str}\n")
_raw_text(p, _cap(_tr("print.ticket.waiter_label"), c_meta) + f" {waiter_nick}\n")
if customer_count: