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:
@@ -2,7 +2,7 @@ from core.access.queries import holders_filter
|
||||
from core.errors import XeniaError
|
||||
from core.modules.entitlements import clamp_start, history_floor, history_since, limit
|
||||
from core.timeutil import business_date_of, business_date_window, parse_api_datetime, venue_strftime, to_venue, utcnow
|
||||
from services import tab_books
|
||||
from services import split_bills, tab_books # split_bills: 6F.6, settled lines count, parts never
|
||||
import csv
|
||||
import io
|
||||
import json
|
||||
@@ -164,7 +164,7 @@ def shift_orders_summary(
|
||||
user: User = Depends(require_reports),
|
||||
):
|
||||
"""Items sent (added) per waiter — regardless of payment status."""
|
||||
q = db.query(OrderItem).filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = db.query(OrderItem).filter(split_bills.sold_filter())
|
||||
start = end = None # 6.12a: with a business day there is no window (was a crash)
|
||||
if business_day_id:
|
||||
q = q.join(Order).filter(Order.business_day_id == business_day_id)
|
||||
@@ -496,7 +496,7 @@ def printer_totals(
|
||||
item_ids = []
|
||||
for item_id in item_ids:
|
||||
item = db.query(OrderItem).filter(OrderItem.id == item_id).first()
|
||||
if item and item.status in ("active", "paid"):
|
||||
if item and split_bills.counts_as_sale(item):
|
||||
summary[pid]["items"] += item.quantity
|
||||
val = _item_val(item)
|
||||
summary[pid]["total"] += val
|
||||
@@ -565,7 +565,7 @@ def _build_printer_block(printer_id: int, printer_name: str, logs, tables, db, m
|
||||
item_ids = []
|
||||
for item_id in item_ids:
|
||||
item = db.query(OrderItem).filter(OrderItem.id == item_id).first()
|
||||
if item and item.status in ("active", "paid"):
|
||||
if item and split_bills.counts_as_sale(item):
|
||||
items_count += item.quantity
|
||||
val = _item_val(item)
|
||||
grand_total += val
|
||||
@@ -633,7 +633,7 @@ def print_waiter(
|
||||
tables = {t.id: (t.label or f"T{t.number}") for t in db.query(Table).all()}
|
||||
order_data = []
|
||||
for o in orders:
|
||||
active_items = [i for i in o.items if i.status in ("active", "paid")]
|
||||
active_items = [i for i in o.items if split_bills.counts_as_sale(i)]
|
||||
total = sum(_item_val(i) for i in active_items)
|
||||
order_data.append({
|
||||
"id": o.id,
|
||||
@@ -648,7 +648,7 @@ def print_waiter(
|
||||
})
|
||||
|
||||
items_count = sum(
|
||||
i.quantity for o in orders for i in o.items if i.status in ("active", "paid")
|
||||
i.quantity for o in orders for i in o.items if split_bills.counts_as_sale(i)
|
||||
)
|
||||
grand_total = sum(d["total"] for d in order_data)
|
||||
|
||||
@@ -778,7 +778,7 @@ def print_products(
|
||||
period_label, period_is_workday = _analytics_period(body, db)
|
||||
|
||||
# Build sold-item summary
|
||||
q = db.query(OrderItem).filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = db.query(OrderItem).filter(split_bills.sold_filter())
|
||||
if body.business_day_id:
|
||||
q = q.join(Order).filter(Order.business_day_id == body.business_day_id)
|
||||
elif body.from_dt and body.to_dt:
|
||||
@@ -837,7 +837,7 @@ def print_categories(
|
||||
|
||||
period_label, period_is_workday = _analytics_period(body, db)
|
||||
|
||||
q = db.query(OrderItem).filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = db.query(OrderItem).filter(split_bills.sold_filter())
|
||||
if body.business_day_id:
|
||||
q = q.join(Order).filter(Order.business_day_id == body.business_day_id)
|
||||
elif body.from_dt and body.to_dt:
|
||||
@@ -974,7 +974,7 @@ def product_performance(
|
||||
from models.product import Product
|
||||
from models.waste import WasteLog
|
||||
|
||||
q = db.query(OrderItem).filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = db.query(OrderItem).filter(split_bills.sold_filter())
|
||||
_since = history_since(from_dt, 'reports')
|
||||
if _since:
|
||||
q = q.filter(OrderItem.added_at >= _since)
|
||||
@@ -1337,7 +1337,7 @@ def category_performance(
|
||||
):
|
||||
from models.product import Product, Category
|
||||
|
||||
q = db.query(OrderItem).filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = db.query(OrderItem).filter(split_bills.sold_filter())
|
||||
_since = history_since(from_dt, 'reports')
|
||||
if _since:
|
||||
q = q.filter(OrderItem.added_at >= _since)
|
||||
@@ -1504,7 +1504,7 @@ def printer_history(
|
||||
order_total = sum(
|
||||
_item_val(i)
|
||||
for i in order.items
|
||||
if i.status in ("active", "paid")
|
||||
if split_bills.counts_as_sale(i)
|
||||
)
|
||||
if log.success and log.order_id not in seen_order_totals:
|
||||
seen_order_totals[log.order_id] = order_total
|
||||
@@ -1713,7 +1713,7 @@ def prep_zones_report(
|
||||
q = q.filter(Order.opened_at <= parse_api_datetime(to_dt))
|
||||
if business_day_id:
|
||||
q = q.filter(Order.business_day_id == business_day_id)
|
||||
q = q.filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = q.filter(split_bills.sold_filter())
|
||||
items = q.all()
|
||||
|
||||
# Aggregate per zone
|
||||
@@ -1839,7 +1839,7 @@ def print_prep_zone(
|
||||
q = q.filter(Order.opened_at <= parse_api_datetime(body.to_dt))
|
||||
if body.business_day_id:
|
||||
q = q.filter(Order.business_day_id == body.business_day_id)
|
||||
q = q.filter(OrderItem.status.in_(["active", "paid"]))
|
||||
q = q.filter(split_bills.sold_filter())
|
||||
items = q.all()
|
||||
|
||||
product_counts: dict[str, dict] = {}
|
||||
|
||||
Reference in New Issue
Block a user