feat(connect): the site side of online orders: fee line, customer's time, price check
Plan phase 3S, step S.5. - Pull: an online order keeps the customer's time (orders.requested_for, None = as soon as possible) and delivery area; quick options are stored in the site's entry shape; items get their cost snapshot. - The delivery fee is its own order line: a system product (products.system_key "delivery_fee", lifecycle "system", sold nowhere; services/system_products.py), created on first use in the venue's language with the VAT group most products use. Added printed and served, so kitchen tickets and the KDS never see it; paid at the counter with the items, counted in the shift, on the fiscal receipt with its VAT group. Never listed in the catalogue (products list, export, edit endpoints → 404) and never added by hand. - Price check (services/online_check.py): each line priced as the snapshot prices it, at the order's time, and the fee through the same engine with the site's rules and the cloud's area id; differences kept on orders.online_price_diff and shown. The customer pays what the cloud charged. - Counter: time chip (or as soon as possible), area, fee line, price warning; takeaway is its own kind (was shown as "at the venue") and finishes as "collected". KDS cards show the online reference and the time; kitchen tickets print the reference, the type and the time. - Manager: Online ordering → "The fee on the receipt" (name, VAT group; PUT /api/connect/fees/fee-product, fees.vat_group_unknown); the online orders page shows the time, area and price warning. - Migration 0019. Tests: tests/test_online_site_side.py (6), terminal unit test, e2e (terminal: fee, time, warning, paid in full; manager: fee line settings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Delivery areas and fee rules (plan phase 3S, step S.3). Key: connect_orders.fees.
|
||||
|
||||
GET /api/connect/fees {areas, rules, ordering}
|
||||
GET /api/connect/fees {areas, rules, ordering, fee_product}
|
||||
PUT /api/connect/fees/fee-product the delivery fee line's name and VAT group (S.5)
|
||||
GET /api/connect/fees/ordering the online ordering settings PUT: save them
|
||||
POST /api/connect/fees/areas add an area PUT/DELETE /areas/{id}
|
||||
POST /api/connect/fees/rules add a rule PUT/DELETE /rules/{id}
|
||||
@@ -219,7 +220,53 @@ def _changed():
|
||||
|
||||
@router.get("")
|
||||
def list_fees(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
return {**fees_payload(db), "ordering": ordering_settings(db)}
|
||||
from services import system_products
|
||||
fee_product = system_products.get(db, system_products.DELIVERY_FEE)
|
||||
db.commit()
|
||||
return {**fees_payload(db), "ordering": ordering_settings(db),
|
||||
"fee_product": {**system_products.out(fee_product), "vat_groups": _vat_groups(db)}}
|
||||
|
||||
|
||||
def _vat_groups(db) -> list[dict]:
|
||||
"""The fiscal machine's VAT groups (setting fiscal.vat_groups): [{machine_id, friendly_name}]."""
|
||||
from models.settings import PosSettings
|
||||
row = db.query(PosSettings).filter(PosSettings.key == "fiscal.vat_groups").first()
|
||||
try:
|
||||
groups = json.loads(row.value or "[]") if row else []
|
||||
except (TypeError, ValueError):
|
||||
return []
|
||||
return [{"machine_id": g.get("machine_id"), "friendly_name": g.get("friendly_name")}
|
||||
for g in groups if isinstance(g, dict) and isinstance(g.get("machine_id"), int)]
|
||||
|
||||
|
||||
class FeeProductBody(BaseModel):
|
||||
"""How the delivery fee line is called (on screens and the receipt) and its VAT group."""
|
||||
name: str = Field(min_length=1, max_length=40)
|
||||
vat_group_id: Optional[int] = Field(default=None, ge=1, le=99)
|
||||
|
||||
@field_validator("name")
|
||||
@classmethod
|
||||
def _strip(cls, v: str) -> str:
|
||||
v = v.strip()
|
||||
if not v:
|
||||
raise ValueError("empty")
|
||||
return v
|
||||
|
||||
|
||||
@router.put("/fee-product")
|
||||
def put_fee_product(body: FeeProductBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""The delivery fee's system product (services/system_products.py). Lines already on orders
|
||||
keep the name they were added with; the VAT group counts from the next receipt."""
|
||||
from services import system_products
|
||||
if body.vat_group_id is not None:
|
||||
groups = [g["machine_id"] for g in _vat_groups(db)]
|
||||
if groups and body.vat_group_id not in groups:
|
||||
raise XeniaError("fees.vat_group_unknown", vat_group_id=body.vat_group_id)
|
||||
product = system_products.get(db, system_products.DELIVERY_FEE)
|
||||
product.name = product.fiscal_name = body.name
|
||||
product.fiscal_vat_group_id = body.vat_group_id
|
||||
db.commit()
|
||||
return system_products.out(product)
|
||||
|
||||
|
||||
@router.get("/ordering")
|
||||
|
||||
Reference in New Issue
Block a user