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:
+42
-2
@@ -9,8 +9,8 @@
|
||||
// - a customer display (no sign-in) goes straight into its app
|
||||
// - server unreachable → banner → back by itself
|
||||
// - removed from the manager → back to pairing with a notice and a new code
|
||||
// - 3.3a–d: the counter POS (sale, payment, tables with a waiter's phone, online orders
|
||||
// pulled from a fake cloud exactly as from the real one)
|
||||
// - 3.3a–e: the counter POS (sale, payment, tables with a waiter's phone, online orders
|
||||
// pulled from a fake cloud exactly as from the real one, refunds)
|
||||
// node terminal.mjs
|
||||
import http from 'node:http'
|
||||
import net from 'node:net'
|
||||
@@ -593,6 +593,46 @@ try {
|
||||
JSON.stringify(rejected))
|
||||
r.check('3.3d: …and it leaves the New list', await page.waitForFunction(() => !document.querySelector('[data-testid="online-order"]'), null, { timeout: 5000 })
|
||||
.then(() => true).catch(() => false))
|
||||
|
||||
// ── 3.3e: refunds ───────────────────────────────────────────────────────
|
||||
// fiscal receipts on, with today's text-file bridge: it can't take credit notes yet, so the
|
||||
// cashier is told to issue it on the machine (owner decision 2026-11-15)
|
||||
await api('PUT', '/api/settings/fiscal.enabled', { token: boss, body: { value: 'true' } })
|
||||
const shiftBeforeRefund = await page.evaluate(async () => (await window.__xeniaClient.get('/api/shifts/my')).data)
|
||||
await page.getByTestId('mode-receipts').click()
|
||||
const saleReceipt = page.locator(`[data-testid="receipt"][data-order="${saleOrder}"]`)
|
||||
r.check('3.3e: Receipts lists today\'s paid orders of the cashier\'s shift (the first quick sale too)',
|
||||
await saleReceipt.waitFor({ timeout: 8000 }).then(() => true).catch(() => false) && (await saleReceipt.textContent()).includes(expected))
|
||||
await saleReceipt.click()
|
||||
await page.locator(`[data-testid="receipt-panel"][data-order="${saleOrder}"]`).waitFor({ timeout: 5000 }).catch(() => {})
|
||||
const simpleLine = page.locator('[data-testid="receipt-line"]', { hasText: simple.name })
|
||||
await simpleLine.locator('button').first().click()
|
||||
await page.getByTestId('refund-qty').locator('button').first().click() // 2 → 1
|
||||
r.check('3.3e: tap an item, pick how many → the refund amount', (await page.getByTestId('refund-start').textContent()).includes(simple.price.toFixed(2))
|
||||
&& await page.getByTestId('refund-cash').getAttribute('aria-checked') === 'true')
|
||||
await page.getByTestId('refund-reason-quality').click()
|
||||
await page.getByTestId('refund-start').click()
|
||||
r.check('3.3e: the confirmation names the amount and reminds about the credit note', await shown(page, 'refund-dialog', 5000)
|
||||
&& (await page.getByTestId('refund-dialog').textContent()).includes('credit note'))
|
||||
await sleep(400) // the dialog's entrance
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos-refund.png') })
|
||||
const drawerBeforeRefund = drawerBytes.length
|
||||
await page.getByTestId('refund-confirm').click()
|
||||
r.check('3.3e: refunded → "issue the credit note on the fiscal machine"', await shown(page, 'manual-credit-note', 8000)
|
||||
&& (await page.getByTestId('manual-credit-note').textContent()).includes(simple.price.toFixed(2)))
|
||||
for (let i = 0; i < 20 && drawerBytes.length === drawerBeforeRefund; i++) await sleep(100)
|
||||
r.check('3.3e: …the cash drawer opened for the money going back', drawerBytes.length > drawerBeforeRefund)
|
||||
const shiftAfterRefund = await page.evaluate(async () => (await window.__xeniaClient.get('/api/shifts/my')).data)
|
||||
r.check('3.3e: …and the shift\'s cash went down by the amount', Math.abs(shiftAfterRefund.cash_refunds - simple.price) < 0.005
|
||||
&& Math.abs((shiftBeforeRefund.net_to_deliver - shiftAfterRefund.net_to_deliver) - simple.price) < 0.005,
|
||||
JSON.stringify({ before: shiftBeforeRefund.net_to_deliver, after: shiftAfterRefund.net_to_deliver, refunds: shiftAfterRefund.cash_refunds }))
|
||||
await page.getByTestId('manual-credit-note-ok').click()
|
||||
r.check('3.3e: the order shows what was given back; one of the two is still refundable',
|
||||
await page.waitForFunction(({ order, name }) => document.querySelector('[data-testid="receipt-refunds"]')
|
||||
&& document.querySelector(`[data-testid="receipt"][data-order="${order}"] [data-testid="receipt-refunded"]`)
|
||||
&& [...document.querySelectorAll('[data-testid="receipt-line"]')].some(l => l.textContent.includes(name) && l.textContent.includes('already given back')),
|
||||
{ order: saleOrder, name: simple.name }, { timeout: 8000 }).then(() => true).catch(() => false))
|
||||
await api('PUT', '/api/settings/fiscal.enabled', { token: boss, body: { value: 'false' } })
|
||||
await page.getByTestId('mode-sale').click()
|
||||
drawerServer.close()
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
|
||||
Reference in New Issue
Block a user