- services/fiscal/: one driver interface (prepare_receipt / prepare_credit_note -> send,
credit_notes flag, status); the dTEC100extra folder bridge moved into txt_file.py as the
first driver, same command files. fiscal_service.py removed, callers moved.
- Refunds: models/refund.py + Alembic 0016 (refunds, refund_items; ordering.refunds for
existing owners/managers). services/refunds.py: today's business day, the cashier's open
shift, partial quantities, items from another shift need ordering.refunds or a manager's
approval (check()/authorize() return the override row). Paid items are never edited.
- POS: GET /api/pos/receipts, GET /api/pos/receipts/{id}, POST /api/pos/orders/{id}/refund
(cash opens the drawer; fiscal "manual" when the driver can't issue credit notes).
- Shift totals subtract refunds and now count discounts; day close and business-day
reports carry refunds.
- Terminal: Receipts mode (ReceiptsView, ReceiptPanel, logic/refunds.js), en/el texts.
- Tests: test_pos_refunds.py (12), terminal unit +1, terminal.mjs +7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.7 KiB
Python
52 lines
2.7 KiB
Python
"""The fiscal driver interface (plan step 3.3e, D-27).
|
|
|
|
A driver speaks to one kind of fiscal device. Callers never talk to a device directly: they
|
|
ask services.fiscal for the venue's driver (setting `fiscal.type`) and use these methods.
|
|
Adding a machine means adding a module with a FiscalDriver subclass and listing it in
|
|
services/fiscal/__init__.py DRIVERS; nothing else changes.
|
|
|
|
Items are plain dicts built by services.fiscal.build_fiscal_items:
|
|
{"name": str, "qty": int | float, "unit_price": float, "vat_group_id": int}
|
|
Results are dicts: {"success": bool, "reference": str | None, "reply": str | None, "error": str | None}
|
|
(`reference`: what the device or bridge calls this document, e.g. the command file's name).
|
|
|
|
Two steps, so the slow part can run off the request: prepare_*(db, ...) reads the settings and
|
|
builds the document with the request's session and returns send(timeout_seconds) -> result,
|
|
which talks to the device without touching the database. issue_* does both (blocking).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Callable
|
|
|
|
Send = Callable[[int], dict]
|
|
|
|
|
|
class FiscalDriver:
|
|
key: str = ""
|
|
name: str = ""
|
|
# Whether issue_credit_note works. A driver without it: refunds are still recorded and the
|
|
# cashier is told to issue the credit note on the machine itself (owner decision 2026-11-15).
|
|
credit_notes: bool = False
|
|
|
|
def prepare_receipt(self, db, items: list[dict], method: str, total: float) -> Send:
|
|
"""A sales receipt, ready to send."""
|
|
raise NotImplementedError
|
|
|
|
def prepare_credit_note(self, db, items: list[dict], method: str, total: float, original: dict | None = None) -> Send:
|
|
"""A credit note for refunded items, ready to send. `original`: what is known about the
|
|
receipt being refunded ({"order_id", "reference"}), for devices that need it."""
|
|
raise NotImplementedError(f"{self.key}: credit notes are not supported")
|
|
|
|
def issue_receipt(self, db, items: list[dict], method: str, total: float, timeout_seconds: int = 30) -> dict:
|
|
"""Issue a sales receipt and wait for the device's answer (blocking)."""
|
|
return self.prepare_receipt(db, items, method, total)(timeout_seconds)
|
|
|
|
def issue_credit_note(self, db, items: list[dict], method: str, total: float, original: dict | None = None,
|
|
timeout_seconds: int = 30) -> dict:
|
|
"""Issue a credit note and wait for the device's answer (blocking)."""
|
|
return self.prepare_credit_note(db, items, method, total, original)(timeout_seconds)
|
|
|
|
def status(self, db) -> dict:
|
|
"""{"configured": bool, "detail": str | None}: whether the driver has what it needs."""
|
|
return {"configured": True, "detail": None}
|