Files
bonaminandClaude Opus 5.5 3eeafb565a 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>
2026-11-23 10:57:54 +02:00

61 lines
2.6 KiB
Python

"""Caller ID (plan step 3.5): who is calling, matched on the server.
normalise("+30 210-600 1234") -> "2106001234"
match(db, number) -> the active customer whose phone is that number, or None
card(db, customer) -> what the popup shows: name, nickname, phone, email, notes,
visits, total spent, the last 3 orders
Greek numbers come in many shapes (+30…, 0030…, 30… with 12 digits, spaces, dashes, brackets);
moved here from the manager's PhoneListener.jsx so every screen agrees and the browser doesn't
download the whole customer list to match a call.
"""
from __future__ import annotations
import re
RECENT = 3
def normalise(raw: str | None) -> str:
if not raw:
return ""
s = re.sub(r"[\s\-().+/]", "", str(raw))
if s.startswith("0030"):
s = s[4:]
elif s.startswith("30") and len(s) > 10:
s = s[2:]
return s
def match(db, number: str | None):
"""The active customer with this number (the most recently created if several), or None."""
from models.customers import Customer
wanted = normalise(number)
if not wanted:
return None
hits = [c for c in db.query(Customer).filter(Customer.is_active.is_(True), Customer.phone.isnot(None))
.order_by(Customer.id.desc()).all() if normalise(c.phone) == wanted]
return hits[0] if hits else None
def card(db, customer) -> dict:
from models.order import Order
from models.table import Table
orders = db.query(Order).filter(Order.customer_id == customer.id).order_by(Order.opened_at.desc()).all()
done = [o for o in orders if o.status in ("closed", "paid")]
from services.split_bills import counts_as_sale
live = lambda o: [i for i in o.items if counts_as_sale(i)] # noqa: E731 (6F.6: settled lines, not parts)
tables = {t.id: (t.label or f"T{t.number}") for t in db.query(Table).all()}
return {
"id": customer.id, "name": customer.name, "nickname": customer.nickname, "phone": customer.phone,
"email": customer.email, "notes": customer.notes,
"visit_count": len(done),
"total_spent": round(sum(i.unit_price * i.quantity for o in done for i in live(o)), 2),
"recent_orders": [{
"id": o.id, "opened_at": o.opened_at.isoformat() if o.opened_at else None,
"table_name": tables.get(o.table_id) if o.table_id else None, "status": o.status,
"total": round(sum(i.unit_price * i.quantity for i in live(o)), 2),
"item_count": sum(i.quantity for i in live(o)),
} for o in orders[:RECENT]],
}