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:
@@ -1,4 +1,4 @@
|
||||
// The counter POS screen (plan steps 3.3a–d). Up to three modes, switched at the top left:
|
||||
// The counter POS screen (plan steps 3.3a–e). Up to four modes, switched at the top left:
|
||||
// - Sale: categories on the left, the product grid with a search, the quick-sale cart on the
|
||||
// right (SaleCart: Charge → payment, 3.3b).
|
||||
// - Tables: the zones on the left and the table list (TablesView); a table opens with the
|
||||
@@ -7,10 +7,12 @@
|
||||
// finished on the left, the orders (OnlineView) and the picked one (OnlinePanel). A new
|
||||
// order rings (and again every 30 s while one waits for an answer) and shows a notice in any
|
||||
// mode; the mode's badge counts the orders waiting.
|
||||
// - Receipts: today's paid orders (the cashier's shift or everyone's) and the picked one
|
||||
// (ReceiptPanel) to give money back for some or all of its items (3.3e).
|
||||
// A tap adds a product (or opens its choices when it has preferences to pick); the (i) button
|
||||
// checks its price without adding it. Every price is the backend's.
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Globe, Info, LayoutGrid, Search, ShoppingBag, X } from 'lucide-react'
|
||||
import { Globe, Info, LayoutGrid, Receipt, Search, ShoppingBag, X } from 'lucide-react'
|
||||
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
|
||||
import { useCan, useModule } from '@xenia/access'
|
||||
import { EmptyState, IconButton, Input, Spinner, useToast } from '@xenia/ui'
|
||||
@@ -22,10 +24,12 @@ import { zoneCounts } from './logic/tables'
|
||||
import OnlinePanel from './OnlinePanel'
|
||||
import OnlineView from './OnlineView'
|
||||
import ProductDialog from './ProductDialog'
|
||||
import ReceiptPanel from './ReceiptPanel'
|
||||
import ReceiptsView from './ReceiptsView'
|
||||
import SaleCart from './SaleCart'
|
||||
import TablePanel from './TablePanel'
|
||||
import TablesView from './TablesView'
|
||||
import { useMenu, useOnline, useTables } from './usePos'
|
||||
import { useMenu, useOnline, useReceipts, useTables } from './usePos'
|
||||
|
||||
const REMIND_MS = 30_000
|
||||
|
||||
@@ -39,7 +43,7 @@ export default function PosScreen() {
|
||||
function Counter({ menu, t }) {
|
||||
const { language } = useLanguage()
|
||||
const { formatMoney } = useFormat()
|
||||
const [mode, setMode] = useState('sale') // sale | tables | online
|
||||
const [mode, setMode] = useState('sale') // sale | tables | online | receipts
|
||||
const [tableId, setTableId] = useState(null) // the open table (tables mode)
|
||||
const [zone, setZone] = useState(null)
|
||||
const [category, setCategory] = useState(() => menu.settings.start_category_id ?? null)
|
||||
@@ -60,6 +64,9 @@ function Counter({ menu, t }) {
|
||||
const [now, setNow] = useState(() => Date.now())
|
||||
const [chimes, setChimes] = useState(0)
|
||||
const waiting = online.data?.incoming.length ?? 0
|
||||
const [receiptScope, setReceiptScope] = useState('mine')
|
||||
const [receiptId, setReceiptId] = useState(null)
|
||||
const receipts = useReceipts(receiptScope, mode === 'receipts')
|
||||
|
||||
const ring = () => { playChime(); setChimes(c => c + 1) }
|
||||
useLiveEvent('online_order_received', data => {
|
||||
@@ -99,7 +106,7 @@ function Counter({ menu, t }) {
|
||||
return (
|
||||
<div className="absolute inset-0 grid grid-cols-[13rem_1fr_24rem] bg-canvas text-ink" data-testid="pos-screen" data-chimes={chimes} lang={language}>
|
||||
<nav className="border-r border-line bg-surface min-h-0 flex flex-col">
|
||||
<div className={`p-2 grid gap-1 border-b border-line ${onlineOn ? 'grid-cols-3' : 'grid-cols-2'}`} role="tablist" aria-label={t('pos.mode.label')}>
|
||||
<div className={`p-2 grid gap-1 border-b border-line ${onlineOn ? 'grid-cols-2' : 'grid-cols-3'}`} role="tablist" aria-label={t('pos.mode.label')}>
|
||||
<ModeButton active={mode === 'sale'} onClick={() => setMode('sale')} icon={ShoppingBag} testId="mode-sale">{t('pos.mode.sale')}</ModeButton>
|
||||
<ModeButton active={mode === 'tables'} onClick={() => { setMode('tables'); leaveTable() }} icon={LayoutGrid} testId="mode-tables"
|
||||
badge={counts.all.busy || null}>{t('pos.mode.tables')}</ModeButton>
|
||||
@@ -107,10 +114,17 @@ function Counter({ menu, t }) {
|
||||
<ModeButton active={mode === 'online'} onClick={() => setMode('online')} icon={Globe} testId="mode-online"
|
||||
badge={waiting || null} alert={waiting > 0}>{t('pos.mode.online')}</ModeButton>
|
||||
)}
|
||||
<ModeButton active={mode === 'receipts'} onClick={() => setMode('receipts')} icon={Receipt} testId="mode-receipts">{t('pos.mode.receipts')}</ModeButton>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto p-2 grid content-start gap-1"
|
||||
data-testid={mode === 'online' ? 'online-lists' : picking ? 'pos-zones' : 'pos-categories'}>
|
||||
{mode === 'online' ? (
|
||||
data-testid={mode === 'online' ? 'online-lists' : mode === 'receipts' ? 'receipt-scopes' : picking ? 'pos-zones' : 'pos-categories'}>
|
||||
{mode === 'receipts' ? (
|
||||
['mine', 'all'].map(sc => (
|
||||
<NavButton key={sc} active={receiptScope === sc} onClick={() => setReceiptScope(sc)} testId={`receipts-${sc}`}>
|
||||
{t(`pos.receipts.scope.${sc}`)}
|
||||
</NavButton>
|
||||
))
|
||||
) : mode === 'online' ? (
|
||||
ONLINE_LISTS.map(list => (
|
||||
<NavButton key={list} active={onlineList === list} onClick={() => setOnlineList(list)} testId={`online-list-${list}`}
|
||||
tally={list === 'finished' ? null : online.data?.[list].length}>
|
||||
@@ -137,7 +151,14 @@ function Counter({ menu, t }) {
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{mode === 'online' ? (
|
||||
{mode === 'receipts' ? (
|
||||
<>
|
||||
<main className="flex flex-col min-h-0 min-w-0">
|
||||
<ReceiptsView data={receipts.data} scope={receiptScope} picked={receiptId} onPick={setReceiptId} />
|
||||
</main>
|
||||
<ReceiptPanel orderId={receiptId} />
|
||||
</>
|
||||
) : mode === 'online' ? (
|
||||
<>
|
||||
<main className="flex flex-col min-h-0 min-w-0">
|
||||
<OnlineView data={online.data} list={onlineList} picked={onlineId} onPick={setOnlineId} now={now} />
|
||||
|
||||
Reference in New Issue
Block a user