Skip to content

refactor(printing): migrate backend thermal receipts, KOT, and preview to semantic print model #443

Closed

Description

@khaira777

Refs: #438
Depends on: #442
Can parallel with: F
Related: #437 (behavior preserved at legacy layer), #133

Context

With PrintDocument v1 proven on the preview path, the backend's real print surfaces migrate: classic + compact receipts, backend KOT, and the text preview — while transports (dispatchPrint: TCP:9100, CUPS, Windows raw spooler) remain untouched.

Architectural Decisions Relevant to This Issue

  • Renderers consume PrintData/PrintContext/PrintDocument; they never re-fetch data or recompute totals/tax.
  • Label resolution comes from the kernel/B catalog; direction metadata drives alignment choices per block/value (no global RTL flip).
  • Capability honesty: when the ESC-POS renderer cannot encode a line (unsupported script under current legacy rules), the document still carries the content and the renderer emits its existing explicit warning entries (surfaced via API response + toast). Silent omission stays prohibited; the conditional arabicShaping behavior of the legacy path is preserved exactly as-is during this migration (Not showing Items in Bill #437 contract) and remains marked legacy in tests.
  • Plugin/compliance template rendering is NOT migrated here (G owns localization hooks there; full plugin-on-document migration is a later, separate decision).

Scope / What to do

  1. Refactor formatClassicReceipt + formatCompactReceipt to build from PrintDocument (token-line emission may stay internal to thermal.ts as an implementation detail of the ESC-POS renderer).
  2. Migrate formatKOT to a KOT document variant (single-language policy via kot_language_policy resolved through kernel; station/order/table/time/items/addons/instructions blocks).
  3. Point the preview branch fully onto the same production code path (delete the D-era temporary divergence if any).
  4. Route language resolution end-to-end: request → settings policies → kernel resolution → context.
  5. Extend parity harness runs to cover compact + KOT against their legacy outputs before switching (same fixture matrix; widths 32/42/48).

Compatibility / Migration

  • No persisted schema changes; no transport changes; warnings array shape unchanged.
  • English semantic output must be identical to pre-migration (harness-enforced). Localized output becomes available for tenants whose language setting is non-English.

What NOT to do

  • Do NOT rewrite dispatchPrint, CUPS/WinSpool helpers, or printer profiles.
  • Do NOT migrate browser/WebUSB renderers (F).
  • Do NOT change tax computations or item projection queries (bill-scoped vs order-scoped semantics stay exactly as today).
  • Do NOT introduce raster/shaping techniques (H decides that separately).

Acceptance Criteria

  • Backend receipts (classic+compact), KOT, and preview all render from PrintDocument.
  • Parity harness green for EN baseline across 32/42/48 columns for every migrated surface.
  • fa/es receipt-language tenants receive localized labels end-to-end via existing tenant setting; KOT honors kitchen policy independently.
  • Direction-aware alignment observable for RTL-primary documents where the renderer can express it; LTR islands preserved for amounts/IDs.
  • Warnings behavior unchanged for unsupported scripts; no content silently dropped beyond documented legacy rules.
  • Full backend suites green: printer, bills-print-api, parity.

Verification

npx ts-node --transpile-only -P tests/tsconfig.json tests/print-parity.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/bills-print-api.test.ts
npm run build && npm run lint

Documentation

Update printers doc section on label/language behavior (docs issue #449 finalizes).

Metadata

Metadata

Assignees

Labels

area:backend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions