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:
@@ -20,7 +20,9 @@ Rules (the same as the waiter's options dialog, waiter_pwa ItemOptionsModal.jsx)
|
||||
- quantities: per-choice qty only on multi-select sets, per-add-on qty only on allow_multiple.
|
||||
Anything else → XeniaError("pos.line_invalid", line=n, reason=...), reason one of
|
||||
product_unavailable | unknown_quick | unknown_option | unknown_choice | unknown_sub |
|
||||
choice_required | sub_required | unknown_ingredient | quantity.
|
||||
choice_required | sub_required | unknown_ingredient | quantity | discount.
|
||||
A line may carry `discount_pct` (0–100, whole percent): the quote shows it; selling it needs
|
||||
ordering.prices.modify or a manager's approval (routers/pos.py).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -61,6 +63,7 @@ class Line:
|
||||
entries: list = field(default_factory=list) # selected_options entries
|
||||
removed: list = field(default_factory=list) # ingredient names
|
||||
notes: Optional[str] = None
|
||||
discount_pct: int = 0 # 3.3b: needs ordering.prices.modify (or approval)
|
||||
|
||||
@property
|
||||
def extra(self) -> float:
|
||||
@@ -96,6 +99,10 @@ def resolve_line(db, raw: dict, n: int) -> Line:
|
||||
if isinstance(quantity, bool) or not isinstance(quantity, (int, float)) or quantity <= 0 or quantity > 999:
|
||||
raise _bad(n, "quantity")
|
||||
line = Line(product=product, quantity=quantity, notes=(raw.get("notes") or "").strip() or None)
|
||||
pct = raw.get("discount_pct", 0) or 0
|
||||
if isinstance(pct, bool) or not isinstance(pct, int) or not 0 <= pct <= 100:
|
||||
raise _bad(n, "discount")
|
||||
line.discount_pct = pct
|
||||
|
||||
quick = {q.id: q for q in product.quick_options}
|
||||
for sel in raw.get("quick") or []:
|
||||
@@ -170,8 +177,8 @@ def resolve_line(db, raw: dict, n: int) -> Line:
|
||||
|
||||
def price_lines(db, lines: list[Line], order_type: str, existing_cart: list | None = None):
|
||||
"""[(unit_price, [PriceEvent])] for each line, with the same context POST
|
||||
/api/orders/{id}/items builds: the order's existing items plus this line (the other new
|
||||
lines of the same batch don't count, as there)."""
|
||||
/api/orders/{id}/items builds: the order's existing items, the lines before it in the
|
||||
same batch (at their resolved price), and this line."""
|
||||
from core.timeutil import utcnow
|
||||
from services.pricing import OrderContext, build_active_price_group_ids, resolve_price
|
||||
now = utcnow()
|
||||
@@ -186,4 +193,11 @@ def price_lines(db, lines: list[Line], order_type: str, existing_cart: list | No
|
||||
ctx = OrderContext(channel=channel, now=now, cart_items=cart + [here], active_price_group_ids=active)
|
||||
unit, events = resolve_price(p, line.quantity, line.extra, ctx, db)
|
||||
out.append((unit, events))
|
||||
cart.append({**here, "unit_price": unit})
|
||||
return out
|
||||
|
||||
|
||||
def discount_adjustment(unit_price: float, pct) -> float:
|
||||
"""A line's discount (percent of its unit price) as the order item's price_adjustment
|
||||
(negative, rounded to cents)."""
|
||||
return -round(unit_price * pct / 100.0, 2) if pct else 0.0
|
||||
|
||||
Reference in New Issue
Block a user