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
+14 -6
View File
@@ -81,11 +81,14 @@ def _subs_out(raw):
for s in pos_cart._subs(raw)]
def _product_out(p, price: float) -> dict:
def _product_out(p, price: float, prices: dict | None = None) -> dict:
shared = lambda ps: pos_cart._shared(ps.shared_subset) # noqa: E731
from core import sales_points
return {
"id": p.id, "name": p.name, "description": p.description, "image_url": p.image_url,
"price": round(price, 2), "base_price": round(p.base_price, 2), "unit_type": p.unit_type or "piece",
"price": round(price, 2), "prices": {k: round(v, 2) for k, v in (prices or {}).items()},
"sold_at": [sp for sp in sales_points.sold_at(p) if sp in sales_points.IN_PERSON],
"base_price": round(p.base_price, 2), "unit_type": p.unit_type or "piece",
"tags": _tags(p.tags),
"primary_category_id": p.primary_category_id,
"categories": [{"category_id": m.category_id, "sort_order": m.sort_order} for m in p.memberships],
@@ -117,7 +120,10 @@ def _tags(raw):
@router.get("/menu")
def pos_menu(request: Request, db: Session = Depends(get_db), user=Depends(require(ACCESS))):
"""Categories and the products a cashier can sell (available, active, not service
items), each with its price right now for one unit without options (pricing engine)."""
items, sold at the counter: eating in or to take away, phase 3S), each with its price right
now for one unit without options (pricing engine): `price` for the screen's default order
type, `prices` per counter sales point, `sold_at` (which of the two)."""
from core import sales_points
from models.product import Category, Product, ProductPreferenceSet
from core.access.context import current_device
from core.modules import device_config
@@ -129,14 +135,16 @@ def pos_menu(request: Request, db: Session = Depends(get_db), user=Depends(requi
selectinload(Product.preference_sets).selectinload(ProductPreferenceSet.choices),
selectinload(Product.memberships))
.order_by(Product.sort_order, Product.name).all())
lines = [pos_cart.Line(product=p, quantity=1) for p in products]
prices = pos_cart.price_lines(db, lines, settings["default_order_type"]) if lines else []
products = [p for p in products if set(sales_points.sold_at(p)) & set(sales_points.IN_PERSON)]
by_point = {sp: pos_cart.unit_prices(db, products, sp) for sp in sales_points.IN_PERSON}
default = pos_cart.point_for(settings["default_order_type"])
cats = db.query(Category).order_by(Category.sort_order, Category.name).all()
return {
"settings": settings,
"categories": [{"id": c.id, "name": c.name, "color": c.color, "parent_id": c.parent_id, "sort_order": c.sort_order}
for c in cats],
"products": [_product_out(p, unit) for p, (unit, _) in zip(products, prices)],
"products": [_product_out(p, by_point[default][i], {sp: by_point[sp][i] for sp in sales_points.IN_PERSON})
for i, p in enumerate(products)],
}