feat(backend): module registry, manifests, enable/disable without restart

Platform v2 step 1.3 (APPS_PLATFORM §4, §5.3, D-4, D-19).
- core/modules: Module/Perm/Limit/SettingDef/DeviceApp/Mount model; registry
  that discovers modules/<key>/manifest.py and validates it (keys, kinds,
  dependencies and cycles, permission prefixes and roles, unique settings,
  each router claimed once and importable, device_app only on apps, workers);
  free_tier.py (D-5 constant, used from 1.4)
- 25 manifests (the §4.2 map) with permission keys + default roles derived
  from today's perm_* meaning, limits, device apps and the 55 settings
- main.py mounts every router from the manifests; non-core routers carry
  Depends(module_required(key)) -> 403 module.disabled while off
- site_modules table (revision 0004), cached enablement; disabling a module
  also turns off modules that depend on it; core can't be disabled
- worker supervisor: connect_menu / connect_orders / connect_remote are now
  separate workers (v1's single _connect_loop split), started and stopped as
  their modules turn on and off; crashes are logged and restarted
- GET /api/platform/bootstrap (venue name/tz/language/currency, effective
  modules, user, language, role-template permission keys), GET /modules,
  PUT /modules/{key}
- settings API derives its key list and defaults from the manifests
- reports router split: history endpoints on history_router (`history`
  module, free tier later) under the same /api/reports prefix
- tests: registry validation, mount coverage, toggle round-trip, dependency
  propagation, bootstrap/catalogue shape, supervisor; pack rule CS-13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 17:46:52 +02:00
co-authored by Claude Opus 5.5
parent 968b6c78fb
commit 231a97c186
69 changed files with 1396 additions and 195 deletions
@@ -0,0 +1,54 @@
"""Module manifest — see core/modules/model.py and APPS_PLATFORM §4."""
from core.modules.model import Module, Mount, Perm, SettingDef
MODULE = Module(
key='ordering',
kind='feature',
name='Ordering',
description='Orders, payments, business day, shifts, cash and kitchen printing.',
depends=('catalog',),
permissions=(
Perm('ordering.orders.open', 'Open orders and add items', roles=('owner', 'store_manager', 'barista', 'barman', 'waiter')),
Perm('ordering.orders.close', 'Take payments and close orders', roles=('owner', 'store_manager', 'barista', 'barman', 'waiter')),
Perm('ordering.orders.cancel', 'Cancel items already sent', roles=('owner', 'store_manager')),
Perm('ordering.prices.modify', "Change an item's price", roles=('owner',)),
Perm('ordering.business_day.manage', 'Open and close the business day', roles=('owner', 'store_manager', 'staff_manager')),
),
settings=(
SettingDef('business_day.force_close_allowed', 'true', 'Allow force-closing business day with open tables', type='bool'),
SettingDef('business_day.rollover_hour', '6', 'Hour (0-23, venue time) before which a newly opened business day counts as the previous date. Default 6.', type='int'),
SettingDef('orders.auto_close_on_full_payment', 'false', "Automatically close the table order when all items have been paid: 'true' | 'false'", type='bool'),
SettingDef('orders.bypass_kds_serve', 'false', "Skip KDS pending/serve flow — new orders and items are immediately marked as served: 'true' | 'false'", type='bool'),
SettingDef('orders.courses', '[]', 'JSON array of course objects [{id, name, color}] defining available courses', type='json'),
SettingDef('orders.courses_enabled', 'false', "Enable per-item course assignment when ordering: 'true' | 'false'", type='bool'),
SettingDef('orders.quick_notes', '["Χωρίς αλάτι","Βγάλτε γρήγορα","Αλλεργία!","Κόψτε σε μικρά κομμάτια","Έξτρα χαρτοπετσέτες"]', 'JSON array of quick-note strings shown in the waiter note tab', type='json'),
SettingDef('orders.waiter_cancellations_allowed', 'true', "Allow waiters with per-account permission to cancel sent orders: 'true' | 'false'", type='bool'),
SettingDef('orders.waiter_price_adjust_allowed', 'false', "Allow waiters to adjust item prices (before or after ordering): 'true' | 'false'", type='bool'),
SettingDef('payments.card_enabled', 'false', "Allow waiters to record card payments (in addition to cash): 'true' | 'false'", type='bool'),
SettingDef('payments.waiter_revert_allowed', 'false', "Allow waiters to revert individual paid items back to unpaid: 'true' | 'false'", type='bool'),
SettingDef('print.beep_on_ticket', 'true', "Play beep when a kitchen ticket prints: 'true' | 'false'", type='bool'),
SettingDef('print.beep_pattern', 'double', "Beep pattern: 'single' | 'double' | 'triple' | 'long' | 'custom:n1:n2:n3'", type='str'),
SettingDef('print.divider_style', 'dash', 'Divider character used between sections: dash, equals, star, or empty', type='str'),
SettingDef('print.dot_style', 'dot_space:0:0', 'Dot-leader style for item lines: STYLE:SIZE:BOLD where STYLE is dot_space|dot|dash_space|underscore, SIZE is ESC ! base byte (0/16/32/48), BOLD 0|1', type='str'),
SettingDef('print.font_extra', '0:0:0', 'Font for extra/option lines (+ marker): SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_ingredient', '0:0:0', 'Font for removed ingredient lines (- marker): SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_item_name', '16:1:0', 'Font for item name lines: SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_item_note', '0:0:0', 'Font for per-item note lines: SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_meta', '0:0:0', 'Font for table/waiter/time header block: SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_order_note', '0:1:0', 'Font for order-level notes: SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_order_number', '48:1:0', 'Font for order number header: SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_pref', '0:0:0', 'Font for preference choice lines (> marker): SIZE:BOLD:CAPS', type='str'),
SettingDef('print.font_quick', '0:0:0', 'Font for quick option lines (* marker): SIZE:BOLD:CAPS', type='str'),
SettingDef('print.ticket_mode', 'detailed', "Kitchen ticket layout mode: 'detailed' or 'compact'", type='str'),
SettingDef('shifts.hide_revenue_from_waiters', 'false', "Hide ΕΙΣΠΡΑΞΗ and ΠΑΡΑΔ. ΠΟΣΟ stats from waiters in Shift Overview: 'true' | 'false'", type='bool'),
SettingDef('shifts.waiter_self_end', 'true', 'Allow waiters to end their own shifts without manager action', type='bool'),
SettingDef('shifts.waiter_self_start', 'true', 'Allow waiters to start their own shifts without manager action', type='bool'),
SettingDef('flags.display_mode', 'both', "How table flags show on the waiter's table cards: 'both' | 'emoji' | 'color'.", type='str'),
),
routers=(
Mount('routers.orders', '/api/orders'),
Mount('routers.business_day', '/api/business-day'),
Mount('routers.shifts', '/api/shifts'),
Mount('routers.flags', '/api/flags'),
),
)