feat(terminal): quick sale at the counter: cash/card/split, change, cash drawer, fiscal (platform-v2 3.3b)
- POST /api/pos/sales: all checks first (shift, lines, payment split, cash given, discount → ordering.prices.modify or manager approval, fiscal VAT groups), then the existing open_order / add_items / pay_items functions, so tickets, KDS, price events, shift totals and the fiscal receipt work as for any order. - Cash drawer: printer_service.open_cash_drawer (ESC @ + ESC p 0 25 250) to the screen's receipt printer on cash, logged and audited (DRAWER_OPENED / DRAWER_FAILED). - orders._can_access_order: the people assigned to an order may act on it (a cashier's own takeaway order); pos_cart prices a batch with the lines before it, as add_items does. - Terminal: Charge → payment dialog (exact cash pre-selected, quick amounts, change, card, split by line), per-line discounts, sale summary and "Same again". - Tests: backend +6 (socket printer receives the drawer kick, fiscal file in the bridge folder), terminal unit +1, terminal.mjs +9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
// - server unreachable → banner → back by itself
|
||||
// - removed from the manager → back to pairing with a notice and a new code
|
||||
// node terminal.mjs
|
||||
import net from 'node:net'
|
||||
import path from 'node:path'
|
||||
import { chromium } from 'playwright'
|
||||
import { BROWSER_CHANNEL, OUT, reporter, sleep } from './lib/env.mjs'
|
||||
@@ -312,6 +313,12 @@ try {
|
||||
} })
|
||||
const posMenu = await api('GET', '/api/pos/menu', { token: boss })
|
||||
const simple = posMenu.products.find(p => !p.prefs.length && p.id !== burgerP.id && p.categories.every(c => c.category_id !== cats[0].id))
|
||||
// 3.3b: the counter's receipt printer is a local socket that records what it gets (cash drawer)
|
||||
const drawerBytes = []
|
||||
const drawerServer = net.createServer(sock => { const chunks = []; sock.on('data', c => chunks.push(c)); sock.on('end', () => drawerBytes.push(Buffer.concat(chunks))) })
|
||||
await new Promise(res => drawerServer.listen(0, '127.0.0.1', res))
|
||||
const receipt = await api('POST', '/api/system/printers', { token: boss, body: { name: 'Counter receipt', ip_address: '127.0.0.1', port: drawerServer.address().port, is_active: true } })
|
||||
await api('PATCH', `/api/devices/${kitchen.id}`, { token: boss, body: { config: { receipt_printer_id: receipt.id } } })
|
||||
await page.locator(`[data-user="${mgr.id}"]`).click()
|
||||
await page.getByLabel('Password').fill('password')
|
||||
await page.getByRole('button', { name: 'Sign in' }).click()
|
||||
@@ -363,6 +370,44 @@ try {
|
||||
&& (await page.getByTestId('line-qty').nth(1).textContent()).includes('2') && (await page.getByTestId('cart-total').textContent()).includes(expected),
|
||||
`${await page.getByTestId('cart-total').textContent()} vs ${expected}`)
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos.png') })
|
||||
|
||||
// ── 3.3b: charge it ──────────────────────────────────────────────────────
|
||||
const cartTotal = Number(expected)
|
||||
await page.getByTestId('charge').click() // tap 1
|
||||
await page.getByTestId('payment-dialog').waitFor({ timeout: 5000 })
|
||||
r.check('3.3b: Charge opens the payment on cash with the exact amount', await page.getByTestId('pay-cash').getAttribute('aria-checked') === 'true'
|
||||
&& (await page.getByTestId('change').textContent()).includes('0.00'))
|
||||
await page.getByTestId('quick-amount').nth(1).click()
|
||||
const givenNow = Number((await page.getByTestId('cash-given').inputValue()).replace(',', '.'))
|
||||
const changeText = await page.getByTestId('change').textContent()
|
||||
r.check('3.3b: a quick amount shows the change', changeText.includes((givenNow - cartTotal).toFixed(2)), `${givenNow} → ${changeText}`)
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos-pay.png') })
|
||||
await page.getByTestId('pay-confirm').click() // tap 2 (3 with typing an amount)
|
||||
r.check('3.3b: paid → the cart shows the change and is ready for the next sale', await shown(page, 'sale-done', 10_000)
|
||||
&& (await page.getByTestId('sale-change').textContent()).includes((givenNow - cartTotal).toFixed(2)) && await page.getByTestId('cart-line').count() === 0)
|
||||
await page.waitForFunction(() => true, null, { timeout: 100 })
|
||||
for (let i = 0; i < 20 && !drawerBytes.length; i++) await sleep(100)
|
||||
r.check('3.3b: the cash drawer opened (ESC p 0 25 250 to the receipt printer)',
|
||||
drawerBytes.some(b => b.includes(Buffer.from([0x1b, 0x70, 0x00, 0x19, 0xfa]))) && (await page.getByTestId('sale-done').textContent()).includes('Drawer opened'))
|
||||
const myShift = await page.evaluate(async () => (await window.__xeniaClient.get('/api/shifts/my')).data)
|
||||
r.check('3.3b: the sale is in the cashier\'s shift cash', Math.abs(myShift.cash_sales - cartTotal) < 0.005 && Math.abs(myShift.net_to_deliver - (cartTotal + 20)) < 0.005,
|
||||
JSON.stringify({ cash: myShift.cash_sales, net: myShift.net_to_deliver }))
|
||||
const saleOrder = Number(await page.getByTestId('sale-done').getAttribute('data-order'))
|
||||
const kdsSeen = (await api('GET', '/api/kds/orders', { token: boss })).orders.some(o => o.id === saleOrder)
|
||||
r.check('3.3b: the kitchen got the order like any other (KDS)', kdsSeen)
|
||||
|
||||
await page.getByTestId('same-again').click()
|
||||
r.check('3.3b: "Same again" puts the last sale back in the cart', await page.getByTestId('cart-line').count() === 2)
|
||||
await page.waitForFunction(x => document.querySelector('[data-testid="cart-total"]')?.textContent.includes(x), expected, { timeout: 5000 }).catch(() => {})
|
||||
await page.getByTestId('charge').click()
|
||||
await page.getByTestId('pay-card').click()
|
||||
const drawerBefore = drawerBytes.length
|
||||
await page.getByTestId('pay-confirm').click()
|
||||
r.check('3.3b: a card payment is recorded as card, no drawer', await page.getByTestId('sale-done').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||||
&& (await page.getByTestId('sale-done').textContent()).includes('Card') && !(await page.getByTestId('sale-done').textContent()).includes('Drawer'))
|
||||
await sleep(300)
|
||||
r.check('3.3b: …and the drawer stayed shut', drawerBytes.length === drawerBefore)
|
||||
drawerServer.close()
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
|
||||
// ── a customer display: no sign-in ───────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user