feat: sales points, offerings and prices per sales point (platform-v2 phase 3S, step S.1)

- core/sales_points.py: in_store, in_store_takeaway, qr_table, online_takeaway,
  online_delivery, online_preorder (+ old channel names mapped).
- Alembic 0017: orders.sales_point (backfilled), products.sold_at (from digital_visible),
  digital_price/digital_discount -> item price modifiers for the QR menu and online,
  order_channel conditions -> sales points; drops the three digital columns.
- Every order records its sales point; the pricing engine's channel is it; items not sold
  there are refused (order.not_sold_here, pos.line_invalid not_sold_here).
- POS menu: only what the counter sells, prices per counter sales point; the screen shows
  the order type's products and prices. Waiter app asks for in-person products.
- Cloud snapshot: products sold by the customer apps, priced by the engine.
- Manager: product "Where it's sold" tab; pricing condition shows sales points.
- Products API, catalogue export/import carry sold_at.
- Tests: test_sales_points.py (8, incl. the migration), access +1, terminal +1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 11:00:40 +02:00
co-authored by Claude Opus 5.5
parent f2182dcb37
commit 1b468fe44b
30 changed files with 700 additions and 156 deletions
+32 -6
View File
@@ -20,7 +20,8 @@ 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 | discount.
choice_required | sub_required | unknown_ingredient | quantity | discount | not_sold_here
(the product isn't sold at this sales point, phase 3S).
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).
"""
@@ -30,9 +31,15 @@ import json
from dataclasses import dataclass, field
from typing import Optional
from core import sales_points
from core.errors import XeniaError
CHANNELS = {"here": "pos", "takeaway": "takeaway"}
POINTS = {"here": sales_points.IN_STORE, "takeaway": sales_points.IN_STORE_TAKEAWAY}
def point_for(order_type: str | None) -> str:
"""The counter's sales point for an order type (phase 3S)."""
return POINTS.get(order_type or "here", sales_points.IN_STORE)
def _subs(raw) -> list[dict]:
@@ -175,19 +182,22 @@ def resolve_line(db, raw: dict, n: int) -> Line:
return line
def price_lines(db, lines: list[Line], order_type: str, existing_cart: list | None = None):
def price_lines(db, lines: list[Line], order_type: str, existing_cart: list | None = None, point: str | None = None):
"""[(unit_price, [PriceEvent])] for each line, with the same context POST
/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."""
same batch (at their resolved price), and this line. The sales point is the order type's
at the counter unless given; a product not sold there → pos.line_invalid not_sold_here."""
from core.timeutil import utcnow
from services.pricing import OrderContext, build_active_price_group_ids, resolve_price
now = utcnow()
active = build_active_price_group_ids(db, now)
channel = CHANNELS.get(order_type, "pos")
channel = point or point_for(order_type)
cart = list(existing_cart or [])
out = []
for line in lines:
for n, line in enumerate(lines):
p = line.product
if not sales_points.is_sold_at(p, channel):
raise _bad(n, "not_sold_here")
here = {"product_id": p.id, "category_id": p.primary_category_id, "category_ids": p.category_ids,
"quantity": line.quantity, "unit_price": p.base_price + line.extra}
ctx = OrderContext(channel=channel, now=now, cart_items=cart + [here], active_price_group_ids=active)
@@ -197,6 +207,22 @@ def price_lines(db, lines: list[Line], order_type: str, existing_cart: list | No
return out
def unit_prices(db, products, point: str) -> list[float]:
"""Each product's price for one unit without options at a sales point, right now, priced
on its own (an empty cart): what a menu shows."""
from core.timeutil import utcnow
from services.pricing import OrderContext, build_active_price_group_ids, resolve_price
now = utcnow()
active = build_active_price_group_ids(db, now)
out = []
for p in products:
here = {"product_id": p.id, "category_id": p.primary_category_id, "category_ids": p.category_ids,
"quantity": 1, "unit_price": p.base_price}
ctx = OrderContext(channel=point, now=now, cart_items=[here], active_price_group_ids=active)
out.append(resolve_price(p, 1, 0.0, ctx, db)[0])
return out
def order_cart(order) -> list[dict]:
"""An order's active items as the pricing engine's cart context (what POST
/api/orders/{id}/items starts from, and what a table's quote starts from, 3.3c)."""