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:
@@ -0,0 +1,53 @@
|
||||
// Refunds at the counter (plan step 3.3e): what the cashier picks on a paid order and what it
|
||||
// adds up to. The backend checks and computes everything again (POST /api/pos/orders/{id}/refund);
|
||||
// this file only helps the screen. Pure: unit-tested in Node (tests/pos.test.mjs).
|
||||
|
||||
const round2 = n => Math.round(n * 100) / 100
|
||||
|
||||
/** Items counted by the piece can be refunded one at a time; weighed ones (kg, litre…) as a whole. */
|
||||
export function byPiece(item) {
|
||||
return !item.unit_type || item.unit_type === 'piece'
|
||||
}
|
||||
|
||||
/** A new pick (item id → quantity) after tapping an item: all of what's left, or nothing. */
|
||||
export function togglePick(pick, item) {
|
||||
const next = { ...pick }
|
||||
if (next[item.id]) delete next[item.id]
|
||||
else if (item.refundable > 0) next[item.id] = item.refundable
|
||||
return next
|
||||
}
|
||||
|
||||
/** A new pick with this item's quantity set (by the piece, within what's left; 0 removes it). */
|
||||
export function setPickQty(pick, item, qty) {
|
||||
const next = { ...pick }
|
||||
const q = Math.max(0, Math.min(item.refundable, Math.round(qty)))
|
||||
if (q > 0) next[item.id] = q
|
||||
else delete next[item.id]
|
||||
return next
|
||||
}
|
||||
|
||||
/** Everything still refundable on the order. */
|
||||
export function pickAll(items) {
|
||||
return Object.fromEntries(items.filter(i => i.refundable > 0).map(i => [i.id, i.refundable]))
|
||||
}
|
||||
|
||||
/** The pick as the endpoint takes it: [{ item_id, quantity }] (only what's still there). */
|
||||
export function refundLines(items, pick) {
|
||||
return items.filter(i => pick[i.id] > 0).map(i => ({ item_id: i.id, quantity: Math.min(pick[i.id], i.refundable) }))
|
||||
}
|
||||
|
||||
/** What the pick gives back. */
|
||||
export function refundTotal(items, pick) {
|
||||
return round2(items.reduce((s, i) => s + (pick[i.id] > 0 ? i.unit_total * Math.min(pick[i.id], i.refundable) : 0), 0))
|
||||
}
|
||||
|
||||
/** The method the money goes back by, to start with: card if every picked item was paid by card. */
|
||||
export function defaultMethod(items, pick) {
|
||||
const picked = items.filter(i => pick[i.id] > 0)
|
||||
return picked.length && picked.every(i => i.method === 'card') ? 'card' : 'cash'
|
||||
}
|
||||
|
||||
/** Whether a manager has to approve (items paid in another shift; the backend decides). */
|
||||
export function needsApproval(items, pick) {
|
||||
return items.some(i => pick[i.id] > 0 && !i.mine)
|
||||
}
|
||||
Reference in New Issue
Block a user