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
+11 -4
View File
@@ -11,6 +11,7 @@ Lock behaviour (unchanged):
- cloud sets locked=true → lock_pending while a workday is open, locked once it closes
- expiry past grace / site deactivated → likewise never mid-service
"""
from core import sales_points
from core.access.queries import holders_filter
from core.timeutil import utcnow
import asyncio
@@ -269,23 +270,28 @@ async def _push_menu_snapshot():
.join(ProductCategory, ProductCategory.product_id == Product.id)
.filter(
ProductCategory.category_id == cat.id,
Product.digital_visible == 1,
Product.lifecycle_status == "active",
)
.order_by(ProductCategory.sort_order, Product.id)
.all()
)
# sold by the customer apps (phase 3S); priced by the engine for the QR menu
# (S.2 sends a price per sales point)
products = [p for p in products if set(sales_points.sold_at(p)) & set(sales_points.DIGITAL)]
from services.pos_cart import unit_prices
qr_prices = unit_prices(db, products, sales_points.QR_TABLE)
all_products.extend(p for p in products if p not in all_products) # once, even if listed twice
product_list = []
for p in products:
for p, qr_price in zip(products, qr_prices):
product_list.append({
"id": p.id,
"name": p.name,
"digital_name": p.digital_name,
"digital_description": p.digital_description,
"digital_price": p.digital_price,
"digital_price": round(qr_price, 2),
"base_price": p.base_price,
"digital_discount": p.digital_discount,
"digital_discount": 0,
"sold_at": [sp for sp in sales_points.sold_at(p) if sp in sales_points.DIGITAL],
"digital_available": bool(p.digital_available),
"digital_image_url": p.digital_image_url,
"image_url": p.image_url,
@@ -353,6 +359,7 @@ def store_online_orders(db, orders: list[dict]) -> dict:
status="open",
source="online",
order_type="delivery" if cloud_order.get("order_type") == "delivery" else "here",
sales_point=sales_points.for_order(None, "online", cloud_order.get("order_type")),
business_day_id=day.id if day else None,
online_order_ref=cloud_order["public_ref"],
online_order_cloud_id=cloud_order["id"],