feat: foundations for the manager conversion (platform-v2 step 6.1)
- Backend: every HTTPException in routers/ is an error code now (260 raises, ~105 new codes, texts in en + el); XeniaError(detail=...) keeps the three v1-shaped answers old pages read; bad / unknown tokens answer auth.session_ended; test_errors refuses new HTTPExceptions. - Manager: v2.json is the list of pages on the v2 rules: scripts/lint.mjs lints them, tests/v2-guards.test.mjs refuses Greek and colour literals, `strict` paths make set-state-in-effect an error. - src/live/useLiveQuery.js (react-query + live events + refresh on reconnect); Signed in now uses it. - Dead manager files removed (3.1k lines unreachable from main.jsx). - Tests: backend 544 passed, manager unit 33, run-all (no Android) passed (manager's live bell check passed on a rerun). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ from core.errors import XeniaError
|
||||
from core.timeutil import parse_api_datetime, venue_strftime, utcnow
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status, BackgroundTasks
|
||||
from fastapi import APIRouter, Depends, Request, status, BackgroundTasks
|
||||
from core.access.override import require_override
|
||||
from core.access.context import authorize
|
||||
|
||||
@@ -333,7 +333,7 @@ def get_order(order_id: int, db: Session = Depends(get_db), user: User = Depends
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
# Resolve all user IDs referenced by this order in one query
|
||||
user_ids = set()
|
||||
@@ -442,11 +442,11 @@ def open_order(body: OrderCreate, db: Session = Depends(get_db), user: User = De
|
||||
from models.shift import WaiterShift
|
||||
|
||||
if not (holds(user, "core.dashboard.access") or holds(user, "ordering.orders.open")):
|
||||
raise HTTPException(status_code=403, detail="Δεν έχετε δικαίωμα ανοίγματος παραγγελιών")
|
||||
raise XeniaError("access.denied", key='ordering.orders.open')
|
||||
|
||||
active_day = db.query(BusinessDay).filter(BusinessDay.status == "open").first()
|
||||
if not active_day:
|
||||
raise HTTPException(status_code=403, detail="Restaurant is not open — manager must open the business day first")
|
||||
raise XeniaError("business_day.closed")
|
||||
|
||||
if holds(user, "waiter_app.access") and not holds(user, "core.dashboard.access"):
|
||||
active_shift = db.query(WaiterShift).filter(
|
||||
@@ -454,11 +454,11 @@ def open_order(body: OrderCreate, db: Session = Depends(get_db), user: User = De
|
||||
WaiterShift.ended_at == None,
|
||||
).first()
|
||||
if not active_shift:
|
||||
raise HTTPException(status_code=403, detail="You do not have an active shift")
|
||||
raise XeniaError("pos.shift_required", status=403)
|
||||
|
||||
order_type = body.order_type or "here"
|
||||
if order_type not in ("here", "takeaway", "delivery"):
|
||||
raise HTTPException(status_code=400, detail="Invalid order_type")
|
||||
raise XeniaError("validation.choice", field='order_type', value=order_type)
|
||||
|
||||
if body.table_id is not None:
|
||||
existing = db.query(Order).filter(
|
||||
@@ -466,7 +466,7 @@ def open_order(body: OrderCreate, db: Session = Depends(get_db), user: User = De
|
||||
Order.status.in_(["open", "partially_paid", "paid"]),
|
||||
).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="Table already has an open order")
|
||||
raise XeniaError("table.busy")
|
||||
|
||||
from core.sales_points import for_order
|
||||
order = Order(table_id=body.table_id, order_type=order_type, opened_by=user.id, business_day_id=active_day.id,
|
||||
@@ -566,7 +566,7 @@ def quote_lines(body: QuoteRequest, db: Session = Depends(get_db), user: User =
|
||||
if order is None:
|
||||
raise XeniaError("order.not_found", order_id=body.order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
existing, order_type, point = pos_cart.order_cart(order), order.order_type or "here", of_order(order)
|
||||
lines, manual = _resolve_lines(db, body.lines, point)
|
||||
try:
|
||||
@@ -594,7 +594,7 @@ def add_items(order_id: int, body: AddLinesRequest, request: Request, db: Sessio
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
lines, manual = _resolve_lines(db, body.lines, of_order(order))
|
||||
approval = None
|
||||
if any(manual) or any(line.discount_pct for line in lines):
|
||||
@@ -628,9 +628,9 @@ def add_priced_items(order_id: int, body: AddItemsRequest, db: Session, user: Us
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
if order.status not in ("open", "partially_paid", "paid"):
|
||||
raise HTTPException(status_code=400, detail="Order is not open")
|
||||
raise XeniaError("order.not_open")
|
||||
|
||||
# Adding items to a fully-paid order reopens it — partially_paid since prior items were paid
|
||||
if order.status == "paid":
|
||||
@@ -653,7 +653,7 @@ def add_priced_items(order_id: int, body: AddItemsRequest, db: Session, user: Us
|
||||
for item_in in body.items:
|
||||
product = db.query(Product).filter(Product.id == item_in.product_id).first()
|
||||
if not product or not product.is_available:
|
||||
raise HTTPException(status_code=400, detail=f"Product {item_in.product_id} not available")
|
||||
raise XeniaError("order.product_unavailable", product_id=item_in.product_id)
|
||||
if not is_sold_at(product, order_channel):
|
||||
raise XeniaError("order.not_sold_here", name=product.name)
|
||||
|
||||
@@ -863,7 +863,7 @@ def retry_print(
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
unprinted_ids = [item.id for item in order.items if not item.printed and item.status == "active"]
|
||||
if not unprinted_ids:
|
||||
@@ -878,7 +878,7 @@ def retry_print(
|
||||
def edit_item(order_id: int, item_id: int, notes: Optional[str] = None, db: Session = Depends(get_db), user: User = Depends(require_manager)):
|
||||
item = db.query(OrderItem).filter(OrderItem.id == item_id, OrderItem.order_id == order_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
raise XeniaError("order.item_not_found")
|
||||
if notes is not None:
|
||||
item.notes = notes
|
||||
db.commit()
|
||||
@@ -902,7 +902,7 @@ def cancel_item(
|
||||
|
||||
is_manager = holds(user, "core.dashboard.access")
|
||||
if not is_manager and not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
approval = None
|
||||
if not is_manager and not _waiter_can_cancel(user, db):
|
||||
# a manager may approve this one cancellation with their PIN (D-10)
|
||||
@@ -910,9 +910,9 @@ def cancel_item(
|
||||
|
||||
item = db.query(OrderItem).filter(OrderItem.id == item_id, OrderItem.order_id == order_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
raise XeniaError("order.item_not_found")
|
||||
if item.status == "paid":
|
||||
raise HTTPException(status_code=400, detail="Το αντικείμενο έχει ήδη πληρωθεί")
|
||||
raise XeniaError("order.item_paid")
|
||||
|
||||
now = utcnow()
|
||||
item.status = "cancelled"
|
||||
@@ -949,7 +949,7 @@ def pay_items(order_id: int, body: PayItemsRequest, request: Request, db: Sessio
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
_need(request, db, user, "ordering.orders.close", target=f"order:{order_id}")
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
from models.shift import WaiterShift
|
||||
from services.fiscal import (
|
||||
@@ -969,10 +969,7 @@ def pay_items(order_id: int, body: PayItemsRequest, request: Request, db: Sessio
|
||||
missing = validate_items_for_fiscal(items, db)
|
||||
if missing:
|
||||
names = ", ".join(missing)
|
||||
raise HTTPException(
|
||||
status_code=422,
|
||||
detail=f"Fiscal printing is ON but the following products have no VAT group assigned: {names}"
|
||||
)
|
||||
raise XeniaError("pos.fiscal_vat_missing", names=names)
|
||||
|
||||
now = utcnow()
|
||||
active_shift = db.query(WaiterShift).filter(
|
||||
@@ -1042,7 +1039,7 @@ def revert_payment(order_id: int, body: RevertPaymentRequest, request: Request,
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
# ordering.payments.revert (owners, store managers); others with a manager's PIN (4.3)
|
||||
approval = _need(request, db, user, "ordering.payments.revert", target=f"order:{order_id}")
|
||||
|
||||
@@ -1053,7 +1050,7 @@ def revert_payment(order_id: int, body: RevertPaymentRequest, request: Request,
|
||||
).all()
|
||||
|
||||
if not items:
|
||||
raise HTTPException(status_code=404, detail="No paid items found to revert")
|
||||
raise XeniaError("order.nothing_paid")
|
||||
|
||||
reverted_ids = []
|
||||
for item in items:
|
||||
@@ -1090,9 +1087,9 @@ def close_order(order_id: int, request: Request, db: Session = Depends(get_db),
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
_need(request, db, user, "ordering.orders.close", target=f"order:{order_id}")
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
if order.status not in ("paid", "open", "partially_paid"):
|
||||
raise HTTPException(status_code=400, detail="Cannot close order in current status")
|
||||
raise XeniaError("order.cannot_close", status=order.status)
|
||||
|
||||
now = utcnow()
|
||||
|
||||
@@ -1149,7 +1146,7 @@ def pay_items_offline(
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
# Check for duplicate UUID on this order
|
||||
existing_uuid = db.query(OrderAuditLog).filter(
|
||||
@@ -1167,7 +1164,7 @@ def pay_items_offline(
|
||||
|
||||
# Reject empty payments — client had no offline snapshot for this table
|
||||
if not items and not is_duplicate:
|
||||
raise HTTPException(status_code=400, detail="No active items found — payment rejected")
|
||||
raise XeniaError("order.no_active_items")
|
||||
|
||||
# Use the client-recorded offline timestamp as paid_at so audit reflects real payment time
|
||||
try:
|
||||
@@ -1244,7 +1241,7 @@ def cancel_order(
|
||||
|
||||
is_manager = holds(user, "core.dashboard.access")
|
||||
if not is_manager and not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
approval = None
|
||||
if not is_manager and not _waiter_can_cancel(user, db):
|
||||
# a manager may approve this one cancellation with their PIN (D-10)
|
||||
@@ -1301,7 +1298,7 @@ def cancel_items_bulk(
|
||||
|
||||
is_manager = holds(user, "core.dashboard.access")
|
||||
if not is_manager and not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
approval = None
|
||||
if not is_manager and not _waiter_can_cancel(user, db):
|
||||
# a manager may approve this one cancellation with their PIN (D-10)
|
||||
@@ -1359,7 +1356,7 @@ def assign_waiter(order_id: int, body: AssignWaiterRequest, db: Session = Depend
|
||||
OrderWaiter.order_id == order_id, OrderWaiter.waiter_id == body.waiter_id
|
||||
).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="Waiter already assigned")
|
||||
raise XeniaError("order.waiter_assigned")
|
||||
db.add(OrderWaiter(order_id=order_id, waiter_id=body.waiter_id))
|
||||
db.commit()
|
||||
return {"status": "assigned"}
|
||||
@@ -1382,7 +1379,7 @@ def assign_customer(order_id: int, body: AssignCustomerBody, db: Session = Depen
|
||||
if body.customer_id is not None:
|
||||
customer = db.query(Customer).filter(Customer.id == body.customer_id, Customer.is_active == True).first()
|
||||
if not customer:
|
||||
raise HTTPException(status_code=404, detail="Customer not found")
|
||||
raise XeniaError("customer.not_found")
|
||||
order.customer_id = body.customer_id
|
||||
db.commit()
|
||||
broadcast_sync("order_updated", {"order_id": order.id, "table_id": order.table_id, "status": order.status, "action": "customer_assigned"})
|
||||
@@ -1395,7 +1392,7 @@ def remove_waiter(order_id: int, waiter_id: int, db: Session = Depends(get_db),
|
||||
OrderWaiter.order_id == order_id, OrderWaiter.waiter_id == waiter_id
|
||||
).first()
|
||||
if not assignment:
|
||||
raise HTTPException(status_code=404, detail="Assignment not found")
|
||||
raise XeniaError("order.assignment_not_found")
|
||||
db.delete(assignment)
|
||||
db.commit()
|
||||
|
||||
@@ -1416,7 +1413,7 @@ def print_order(
|
||||
|
||||
printer = db.query(Printer).filter(Printer.id == body.printer_id, Printer.is_active == True).first()
|
||||
if not printer:
|
||||
raise HTTPException(status_code=404, detail="Printer not found or inactive")
|
||||
raise XeniaError("printer.not_found")
|
||||
|
||||
table = db.query(Table).filter(Table.id == order.table_id).first()
|
||||
table_name = (table.label or f"T{table.number}") if table else f"#{order.table_id}"
|
||||
@@ -1473,22 +1470,22 @@ def transfer_order(
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
_need(request, db, user, "ordering.orders.open")
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
if order.status not in ("open", "partially_paid", "paid"):
|
||||
raise HTTPException(status_code=400, detail="Order is not active")
|
||||
raise XeniaError("order.not_open")
|
||||
|
||||
target_table = db.query(Table).filter(Table.id == body.target_table_id, Table.is_active == True).first()
|
||||
if not target_table:
|
||||
raise HTTPException(status_code=404, detail="Target table not found")
|
||||
raise XeniaError("table.not_found")
|
||||
if body.target_table_id == order.table_id:
|
||||
raise HTTPException(status_code=400, detail="Table is already assigned to this order")
|
||||
raise XeniaError("order.same_table")
|
||||
|
||||
conflict = db.query(Order).filter(
|
||||
Order.table_id == body.target_table_id,
|
||||
Order.status.in_(["open", "partially_paid", "paid"]),
|
||||
).first()
|
||||
if conflict:
|
||||
raise HTTPException(status_code=400, detail="Target table already has an active order")
|
||||
raise XeniaError("table.busy")
|
||||
|
||||
old_table_id = order.table_id
|
||||
order.table_id = body.target_table_id
|
||||
@@ -1518,22 +1515,22 @@ def merge_order(
|
||||
"""
|
||||
source = db.query(Order).filter(Order.id == order_id).first()
|
||||
if not source:
|
||||
raise HTTPException(status_code=404, detail="Source order not found")
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
_need(request, db, user, "ordering.orders.open")
|
||||
if not _can_access_order(source, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
if source.status not in ("open", "partially_paid", "paid"):
|
||||
raise HTTPException(status_code=400, detail="Source order is not active")
|
||||
raise XeniaError("order.not_open")
|
||||
|
||||
target = db.query(Order).filter(Order.id == body.target_order_id).first()
|
||||
if not target:
|
||||
raise HTTPException(status_code=404, detail="Target order not found")
|
||||
raise XeniaError("order.target_not_found")
|
||||
if not _can_access_order(target, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied to target order")
|
||||
raise XeniaError("order.not_yours")
|
||||
if target.status not in ("open", "partially_paid", "paid"):
|
||||
raise HTTPException(status_code=400, detail="Target order is not active")
|
||||
raise XeniaError("order.not_open")
|
||||
if source.id == target.id:
|
||||
raise HTTPException(status_code=400, detail="Cannot merge an order with itself")
|
||||
raise XeniaError("order.same_order")
|
||||
|
||||
# Move all items to target order
|
||||
moved_item_ids = []
|
||||
@@ -1598,18 +1595,15 @@ def split_item(
|
||||
OrderItem.id == item_id, OrderItem.order_id == order_id
|
||||
).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
raise XeniaError("order.item_not_found")
|
||||
if item.status != "active":
|
||||
raise HTTPException(status_code=400, detail="Only active items can be split")
|
||||
raise XeniaError("order.item_not_active")
|
||||
if body.quantity <= 0 or body.quantity >= item.quantity:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Split quantity must be between 1 and {item.quantity - 1}"
|
||||
)
|
||||
raise XeniaError("order.split_quantity", max=item.quantity - 1)
|
||||
|
||||
order = db.query(Order).filter(Order.id == order_id).first()
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
# Reduce original item
|
||||
item.quantity -= body.quantity
|
||||
@@ -1656,13 +1650,13 @@ def adjust_item_price(
|
||||
OrderItem.id == item_id, OrderItem.order_id == order_id
|
||||
).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
raise XeniaError("order.item_not_found")
|
||||
if item.status != "active":
|
||||
raise HTTPException(status_code=400, detail="Only active items can have price adjusted")
|
||||
raise XeniaError("order.item_not_active")
|
||||
|
||||
order = db.query(Order).filter(Order.id == order_id).first()
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
_need(request, db, user, "ordering.prices.modify", target=f"order:{order_id} item:{item_id}")
|
||||
|
||||
item.price_adjustment = body.price_adjustment
|
||||
@@ -1696,10 +1690,10 @@ def apply_waiter_discount(
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
_need(request, db, user, "pricing.discounts.apply", target=f"order:{order_id}")
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
if body.discount_percent <= 0 or body.discount_percent > 100:
|
||||
raise HTTPException(status_code=400, detail="discount_percent must be between 0 and 100")
|
||||
raise XeniaError("validation.range", field='discount_percent', min=0, max=100)
|
||||
|
||||
# Fetch all target items
|
||||
items = db.query(OrderItem).filter(
|
||||
@@ -1708,12 +1702,12 @@ def apply_waiter_discount(
|
||||
OrderItem.status == "active",
|
||||
).all()
|
||||
if not items:
|
||||
raise HTTPException(status_code=404, detail="No active items found for given IDs")
|
||||
raise XeniaError("order.no_active_items", status=404)
|
||||
|
||||
item_unit_prices = {i.id: i.unit_price + i.price_adjustment for i in items}
|
||||
|
||||
if not discounts_enabled(db):
|
||||
raise HTTPException(status_code=403, detail="Discounts are globally disabled")
|
||||
raise XeniaError("order.discounts_off")
|
||||
|
||||
# Validate limits before touching anything. Beyond them: pricing.discounts.over_limit,
|
||||
# or a manager approves this one discount with their PIN (D-10).
|
||||
@@ -1846,13 +1840,13 @@ def cancel_print_job(
|
||||
"""Staff cancels a pending print job (failed print, still retrying)."""
|
||||
pj = db.query(PrintJob).filter(PrintJob.id == job_id, PrintJob.order_id == order_id).first()
|
||||
if not pj:
|
||||
raise HTTPException(status_code=404, detail="Print job not found")
|
||||
raise XeniaError("print_job.not_found")
|
||||
if pj.status != "pending":
|
||||
raise HTTPException(status_code=400, detail="Only pending print jobs can be cancelled")
|
||||
raise XeniaError("print_job.not_pending")
|
||||
|
||||
order = db.query(Order).filter(Order.id == order_id).first()
|
||||
if not order or not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
from datetime import datetime, timezone
|
||||
pj.status = "cancelled"
|
||||
@@ -1889,7 +1883,7 @@ def update_customer_count(
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
order.customer_count = body.customer_count
|
||||
db.commit()
|
||||
@@ -1911,21 +1905,21 @@ def move_items(
|
||||
_need(request, db, user, "ordering.orders.open")
|
||||
source = db.query(Order).filter(Order.id == order_id).first()
|
||||
if not source:
|
||||
raise HTTPException(status_code=404, detail="Source order not found")
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(source, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
if source.status not in ("open", "partially_paid"):
|
||||
raise HTTPException(status_code=400, detail="Source order is not active")
|
||||
raise XeniaError("order.not_open")
|
||||
|
||||
target = db.query(Order).filter(Order.id == body.target_order_id).first()
|
||||
if not target:
|
||||
raise HTTPException(status_code=404, detail="Target order not found")
|
||||
raise XeniaError("order.target_not_found")
|
||||
if not _can_access_order(target, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied to target order")
|
||||
raise XeniaError("order.not_yours")
|
||||
if target.status not in ("open", "partially_paid"):
|
||||
raise HTTPException(status_code=400, detail="Target order is not active")
|
||||
raise XeniaError("order.not_open")
|
||||
if source.id == target.id:
|
||||
raise HTTPException(status_code=400, detail="Source and target orders are the same")
|
||||
raise XeniaError("order.same_order")
|
||||
|
||||
items = db.query(OrderItem).filter(
|
||||
OrderItem.id.in_(body.item_ids),
|
||||
@@ -1933,7 +1927,7 @@ def move_items(
|
||||
OrderItem.status == "active",
|
||||
).all()
|
||||
if not items:
|
||||
raise HTTPException(status_code=400, detail="No active items found to move")
|
||||
raise XeniaError("order.no_active_items")
|
||||
|
||||
moved_ids = []
|
||||
for item in items:
|
||||
@@ -1982,11 +1976,11 @@ def print_synopsis(
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
|
||||
printer = db.query(Printer).filter(Printer.id == body.printer_id, Printer.is_active == True).first()
|
||||
if not printer:
|
||||
raise HTTPException(status_code=404, detail="Printer not found or inactive")
|
||||
raise XeniaError("printer.not_found")
|
||||
|
||||
table = db.query(Table).filter(Table.id == order.table_id).first()
|
||||
table_name = (table.label or f"T{table.number}") if table else f"#{order.table_id}"
|
||||
@@ -2042,13 +2036,13 @@ def put_item_on_tab(
|
||||
if not order:
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
if not order.customer_id:
|
||||
raise HTTPException(status_code=400, detail="Order has no customer assigned — assign a customer first")
|
||||
raise XeniaError("order.no_customer")
|
||||
|
||||
item = db.query(OrderItem).filter(OrderItem.id == item_id, OrderItem.order_id == order_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
raise XeniaError("order.item_not_found")
|
||||
if item.status != "active":
|
||||
raise HTTPException(status_code=400, detail=f"Item is already {item.status} — cannot tab it")
|
||||
raise XeniaError("order.item_not_tabbable", status=item.status)
|
||||
|
||||
# Find or auto-create the customer's open tab
|
||||
tab = db.query(Tab).filter(Tab.customer_id == order.customer_id, Tab.status == "open").first()
|
||||
@@ -2110,7 +2104,7 @@ def combine_items(order_id: int, body: CombineItemsRequest, request: Request, db
|
||||
raise XeniaError("order.not_found", order_id=order_id)
|
||||
_need(request, db, user, "ordering.orders.open", target=f"order:{order_id}")
|
||||
if not _can_access_order(order, user, db):
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
raise XeniaError("order.not_yours")
|
||||
ids = sorted(set(body.item_ids))
|
||||
items = db.query(OrderItem).filter(OrderItem.order_id == order_id, OrderItem.id.in_(ids)).order_by(OrderItem.id).all()
|
||||
if len(items) != len(ids) or len(items) < 2:
|
||||
|
||||
Reference in New Issue
Block a user