feat(backend,waiter,terminal,manager): split the bill by amount

Owner 2026-11-23 (plan 6F.6). Venue setting payments.split_amount (off | two_equal | two_custom |
multiple_equal, each level with the ones before; default off) and payments.split_max_parts (10);
key ordering.payments.split_amount (everyone who takes payments; Alembic 0050 grants it).
POST /api/orders/{id}/split-bills settles the chosen unpaid lines (status 'split': sold, no shift,
no payment method) and adds part lines (system product split_part, "Split bill 1/3", printed and
served; equal parts with the remainder on the last, or two parts with part 1 typed). Parts are paid
like any line (cash, card, tab). POST .../split-bills/{bill}/undo while no part is paid or tabbed.
Counting (services/sales.py): settled lines are the sales, parts never (a refunded part comes off
the settled lines by share); drawers and payment methods count the parts. Older reports use
split_bills.sold_filter / counts_as_sale. Locks: parts can't be cancelled, moved, combined or
re-priced; settled lines are no longer active; closing or cancelling an order with unpaid parts is
refused. Fiscal: one receipt with the settled lines when the last part is paid, with each method's
amount (txt driver: CD per card amount, then CR for cash).
Waiter: Pay -> "Split the amount" (pre-filled from the customers), the split bill above the lines
with Undo. Counter: "By amount" in the payment (quick sale split and paid at once, Q-4; a table's
lines split then paid). Manager: the pay dialog splits, the order shows its split bills, Settings ->
Operation card. Shared rules in @xenia/ordering/split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 10:57:54 +02:00
co-authored by Claude Opus 5.5
parent 72e175ab73
commit 3eeafb565a
54 changed files with 1707 additions and 105 deletions
+15
View File
@@ -129,6 +129,21 @@ test('tables at the counter: state, zones, order lines, what Pay takes (3.3c)',
assert.equal(qtyLabel(0.5, 'liter'), '0.5 L')
})
test('a split bill at the counter: parts are lines, settled lines add up to nothing (6F.6)', async () => {
const { orderLines, orderSums, partPayments, toPay } = await import('../src/apps/pos/logic/tables.js')
const order = { items: [
{ id: 1, product_name: 'Burger', quantity: 1, unit_price: 10, status: 'split', split_bill_id: 4 },
{ id: 2, product_name: 'Freddo', quantity: 2, unit_price: 2.5, status: 'split', split_bill_id: 4 },
{ id: 3, product_name: 'Split bill 1/2', quantity: 1, unit_price: 4.5, status: 'paid', payment_method: 'cash', split_bill_id: 4 },
{ id: 4, product_name: 'Split bill 2/2', quantity: 1, unit_price: 10.5, status: 'active', split_bill_id: 4 },
] }
const lines = orderLines(order)
assert.deepEqual(lines.map(l => [l.id, l.paid, !!l.settled, !!l.part]), [[4, false, false, true], [1, true, true, false], [2, true, true, false], [3, true, false, true]])
assert.deepEqual(orderSums(lines), { total: 15, paid: 4.5, unpaid: 10.5, unpaidIds: [4] })
assert.deepEqual(toPay(lines, []).map(l => l.id), [4])
assert.deepEqual(partPayments([7, 8, 9], ['cash', 'card', 'cash']), [{ method: 'cash', item_ids: [7, 9] }, { method: 'card', item_ids: [8] }])
})
test('online orders: the next step and finding an order (3.3d)', async () => {
const { findOnline, minutesSince, nextStep } = await import('../src/apps/pos/logic/online.js')
assert.deepEqual(nextStep({ status: 'pending_acceptance' }), { kind: 'answer' })