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
+25
View File
@@ -148,3 +148,28 @@ test('online orders: the next step and finding an order (3.3d)', async () => {
assert.equal(minutesSince('2026-11-15T09:57:30Z', at), 2)
assert.equal(minutesSince('2026-11-15T10:01:00Z', at), 0)
})
test('refunds: picking items, quantities, total, method, approval (3.3e)', async () => {
const { byPiece, defaultMethod, needsApproval, pickAll, refundLines, refundTotal, setPickQty, togglePick } = await import('../src/apps/pos/logic/refunds.js')
const coffee = { id: 1, unit_type: 'piece', refundable: 2, unit_total: 3, method: 'cash', mine: true }
const feta = { id: 2, unit_type: 'kg', refundable: 0.25, unit_total: 12, method: 'card', mine: true }
const done = { id: 3, unit_type: 'piece', refundable: 0, unit_total: 5, method: 'card', mine: false }
const items = [coffee, feta, done]
assert.equal(byPiece(coffee), true)
assert.equal(byPiece(feta), false)
let pick = togglePick({}, coffee)
assert.deepEqual(pick, { 1: 2 })
pick = setPickQty(pick, coffee, 1)
assert.deepEqual(refundLines(items, pick), [{ item_id: 1, quantity: 1 }])
assert.equal(refundTotal(items, pick), 3)
assert.deepEqual(setPickQty(pick, coffee, 9), { 1: 2 }, 'not more than what is left')
assert.deepEqual(setPickQty(pick, coffee, 0), {}, '0 removes it')
assert.deepEqual(togglePick(pick, coffee), {}, 'a second tap removes it')
assert.deepEqual(togglePick({}, done), {}, 'nothing left to refund')
assert.deepEqual(pickAll(items), { 1: 2, 2: 0.25 })
assert.equal(refundTotal(items, pickAll(items)), 9)
assert.equal(defaultMethod(items, { 2: 0.25 }), 'card')
assert.equal(defaultMethod(items, pickAll(items)), 'cash')
assert.equal(needsApproval(items, pickAll(items)), false)
assert.equal(needsApproval([{ ...coffee, mine: false }], { 1: 1 }), true)
})