feat(pos): refunds at the counter on a fiscal driver layer (platform-v2 3.3e)

- 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>
This commit is contained in:
2026-11-15 09:44:17 +02:00
co-authored by Claude Opus 5.5
parent d542cf7d34
commit f2182dcb37
32 changed files with 1486 additions and 169 deletions
+32 -2
View File
@@ -1,5 +1,5 @@
// The counter POS's server data (plan steps 3.3a, 3.3c, 3.3d): the cashier's session (shift gate),
// the menu, the cart priced by the backend, the tables, a table's order and online orders. Kept fresh by the
// The counter POS's server data (plan steps 3.3a, 3.3c–e): the cashier's session (shift gate),
// the menu, the cart priced by the backend, the tables, a table's order, online orders and receipts. Kept fresh by the
// live connection, so a waiter's phone and the counter see each other's changes at once.
import { useCallback, useEffect, useRef, useState } from 'react'
import client from '../../api/client'
@@ -129,3 +129,33 @@ export function useOnline(enabled) {
useLiveEvents(ONLINE_EVENTS, soon)
return { data, reload: load }
}
const RECEIPT_EVENTS = ['order_paid', 'order_refunded', 'order_closed']
/** GET /api/pos/receipts: today's paid orders ({ orders }, null while loading); live. */
export function useReceipts(scope, enabled) {
const [data, setData] = useState(null)
const load = useCallback(async () => {
if (!enabled) return
try { setData((await client.get('/api/pos/receipts', { ...quiet, params: { scope } })).data) } catch { /* the shell shows offline */ }
}, [scope, enabled])
const soon = useCoalesced(load)
useEffect(() => { load() }, [load])
useLiveEvent('ready', load)
useLiveEvents(RECEIPT_EVENTS, soon)
return { data, reload: load }
}
/** GET /api/pos/receipts/{id}: one paid order with what's refundable (null id → null); live. */
export function useReceipt(orderId) {
const [receipt, setReceipt] = useState(null)
const load = useCallback(async () => {
if (orderId == null) { setReceipt(null); return }
try { setReceipt((await client.get(`/api/pos/receipts/${orderId}`, quiet)).data) } catch { /* the shell shows offline */ }
}, [orderId])
const soon = useCoalesced(load)
useEffect(() => { load() }, [load])
useLiveEvent('ready', load)
useLiveEvents(RECEIPT_EVENTS, (_type, data) => { if (data?.order_id === orderId) soon() })
return { receipt, reload: load }
}