Owner 2026-11-23 (plan 6F.5). Product flag one_more_enabled (off by default; product editor).
POST /api/orders/{id}/items/{item}/again: a new line like the old one (choices, removed, note,
course), priced now, sent to the kitchen like any new line. Waiter app and the counter's table
panel: +1 beside such lines; the first tap arms it, more taps count up, 'Send +N' sends, 4 s idle
disarms (no stray sends).
POST /api/orders/{id}/items/{item}/quantity: venue setting orders.quantity_change (off | add_only |
add_and_remove, default off), key ordering.items.change_quantity (owner, store manager; Alembic 0049
grants it); up only changes the line, down cuts a cancelled part ('quantity lowered', split_from_id)
and prints a cancellation only when asked (the dialog presets yes while the kitchen hasn't finished).
Waiter: 'Change quantity' in a line's actions (now -> new, -/+). cut_part() now shared with split.
GET /api/orders/{id} items carry the product's one_more_enabled / unit_type, deal ids, split_from_id,
cancel_reason.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
6.4 KiB
Python
198 lines
6.4 KiB
Python
import json
|
|
|
|
from pydantic import BaseModel, field_validator
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
from schemas.base import UTCDatetime
|
|
|
|
|
|
class SelectedOptionInput(BaseModel):
|
|
id: Optional[int] = None
|
|
name: Optional[str] = None
|
|
price_delta: Optional[float] = None
|
|
extra_cost: Optional[float] = None
|
|
# type tags: "quick" | "pref" | "pref_sub" | "extra" | "extra_sub"
|
|
# Omitted by old clients — print code falls back gracefully.
|
|
type: Optional[str] = None
|
|
|
|
|
|
class OrderItemInput(BaseModel):
|
|
product_id: int
|
|
quantity: float
|
|
selected_options: Optional[List[SelectedOptionInput]] = None
|
|
removed_ingredients: Optional[List[str]] = None
|
|
notes: Optional[str] = None
|
|
price_adjustment: Optional[float] = None # on-the-fly price delta, applied at add-time
|
|
is_service_item: bool = False # priceless: print-once ephemeral; priced: saved as real item
|
|
course_id: Optional[int] = None
|
|
source: Optional[str] = None # set by the server (4.8): waiter | counter | qr | online
|
|
# a price changed by hand (6F.3), set by the server: the reason and the approving manager
|
|
price_reason: Optional[str] = None
|
|
price_approved_by: Optional[int] = None
|
|
|
|
|
|
class AddItemsRequest(BaseModel):
|
|
items: List[OrderItemInput]
|
|
order_note: Optional[str] = None # whole-order note, written to Order.notes
|
|
customer_count: Optional[int] = None # number of customers at the table
|
|
|
|
|
|
class ProductNameOut(BaseModel):
|
|
id: int
|
|
name: str
|
|
one_more_enabled: bool = False # 6F.5: the line shows +1
|
|
unit_type: Optional[str] = None
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class OrderItemOut(BaseModel):
|
|
id: int
|
|
order_id: int
|
|
product_id: int
|
|
product: Optional[ProductNameOut] = None
|
|
product_name: Optional[str] = None # name when ordered (D-18); `product` is the live catalogue
|
|
category_id: Optional[int] = None # category when ordered
|
|
category_name: Optional[str] = None
|
|
added_by: int
|
|
quantity: float
|
|
unit_type: str = "piece"
|
|
unit_price: float
|
|
selected_options: Optional[str] = None
|
|
removed_ingredients: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
status: str
|
|
kds_status: str = "pending"
|
|
added_at: UTCDatetime
|
|
printed: bool
|
|
paid_by: Optional[int] = None
|
|
paid_at: Optional[UTCDatetime] = None
|
|
payment_method: Optional[str] = None
|
|
paid_in_shift_id: Optional[int] = None
|
|
price_adjustment: float = 0.0
|
|
course_id: Optional[int] = None
|
|
source: Optional[str] = None # waiter | counter | qr | online (4.8); None = before 4.8
|
|
deal_id: Optional[int] = None
|
|
linked_item_id: Optional[int] = None
|
|
split_from_id: Optional[int] = None # 6F.4: the line it was cut from
|
|
system_key: Optional[str] = None # a line the system added: "delivery_fee" (phase 3S, S.5)
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class PrintResultOut(BaseModel):
|
|
printer_name: str
|
|
success: bool
|
|
error: Optional[str] = None
|
|
|
|
|
|
class AddItemsResponse(BaseModel):
|
|
order: "OrderOut"
|
|
print_results: List[PrintResultOut]
|
|
deal_offers: List[dict] = [] # DealOfferOut dicts — serialized to avoid circular imports
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class OrderCreate(BaseModel):
|
|
table_id: Optional[int] = None
|
|
order_type: Optional[str] = "here" # here | takeaway | delivery
|
|
|
|
|
|
class PayItemsRequest(BaseModel):
|
|
item_ids: List[int]
|
|
payment_method: Optional[str] = None # 'cash' | 'card' | 'other' — optional for now
|
|
|
|
|
|
class OfflinePaymentRequest(BaseModel):
|
|
uuid: str # client-generated UUID, used for duplicate detection
|
|
item_ids: List[int]
|
|
payment_method: Optional[str] = None
|
|
offline_at: Optional[str] = None # ISO timestamp of when payment was taken offline
|
|
|
|
|
|
class AssignWaiterRequest(BaseModel):
|
|
waiter_id: int
|
|
|
|
|
|
class OrderWaiterOut(BaseModel):
|
|
waiter_id: int
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class AuditLogOut(BaseModel):
|
|
id: int
|
|
order_id: int
|
|
event_type: str
|
|
waiter_id: Optional[int] = None
|
|
waiter_name: Optional[str] = None # resolved server-side
|
|
item_ids: Optional[str] = None
|
|
amount: Optional[float] = None
|
|
payment_method: Optional[str] = None
|
|
note: Optional[str] = None
|
|
created_at: UTCDatetime
|
|
offline_at: Optional[str] = None
|
|
is_duplicate: int = 0
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class PrintJobOut(BaseModel):
|
|
id: int
|
|
printer_id: int
|
|
zone_id: Optional[int] = None
|
|
item_ids: str
|
|
copies: int = 1
|
|
status: str
|
|
retry_count: int = 0
|
|
first_attempted_at: Optional[UTCDatetime] = None
|
|
last_attempted_at: Optional[UTCDatetime] = None
|
|
succeeded_at: Optional[UTCDatetime] = None
|
|
cancelled_at: Optional[UTCDatetime] = None
|
|
cancel_reason: Optional[str] = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class OrderOut(BaseModel):
|
|
id: int
|
|
table_id: Optional[int] = None
|
|
opened_by: int
|
|
opened_at: UTCDatetime
|
|
status: str
|
|
closed_at: Optional[UTCDatetime] = None
|
|
closed_by: Optional[int] = None
|
|
notes: Optional[str] = None
|
|
business_day_id: Optional[int] = None
|
|
# Xenia Connect — online order fields
|
|
source: str = "pos"
|
|
online_order_ref: Optional[str] = None
|
|
online_order_cloud_id: Optional[int] = None
|
|
online_status: Optional[str] = None
|
|
online_customer_name: Optional[str] = None
|
|
online_customer_phone: Optional[str] = None
|
|
online_customer_address: Optional[str] = None
|
|
online_customer_notes: Optional[str] = None
|
|
online_order_type: Optional[str] = None
|
|
online_delivery_area: Optional[str] = None
|
|
online_price_diff: Optional[dict] = None # the site's price check (S.5); None = matched
|
|
requested_for: Optional[UTCDatetime] = None # None = as soon as possible
|
|
order_type: str = "here"
|
|
customer_count: Optional[int] = None
|
|
items: List[OrderItemOut] = []
|
|
waiters: List[OrderWaiterOut] = []
|
|
audit_logs: List[AuditLogOut] = []
|
|
print_jobs: List[PrintJobOut] = []
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
@field_validator("online_price_diff", mode="before")
|
|
@classmethod
|
|
def _diff(cls, value):
|
|
if value is None or isinstance(value, dict):
|
|
return value
|
|
try:
|
|
data = json.loads(value)
|
|
except (TypeError, ValueError):
|
|
return None
|
|
return data if isinstance(data, dict) else None
|