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
+17 -6
View File
@@ -7,6 +7,7 @@ from pydantic import BaseModel
from sqlalchemy.orm import Session
from typing import List
from core import sales_points
from database import get_db
from models.product import Product, Category, ProductCategory, ProductOption, ProductQuickOption, ProductIngredient, ProductPreferenceSet, ProductPreferenceChoice, ProductModifierGroup
from models.prep_zone import PrepZone
@@ -263,10 +264,12 @@ def delete_category(category_id: int, db: Session = Depends(get_db), user: User
# ── Products ──────────────────────────────────────────────────────────────────
@router.get("/", response_model=List[ProductOut])
def list_products(all: bool = False, category_id: int | None = None, db: Session = Depends(get_db),
user: User = Depends(get_current_user)):
def list_products(all: bool = False, category_id: int | None = None, sold_at: str | None = None,
db: Session = Depends(get_db), user: User = Depends(get_current_user)):
"""Every product once, with `category_ids` / `categories` (D-23). With `category_id`:
the products LISTED in that category (primary or not), in that category's order."""
the products LISTED in that category (primary or not), in that category's order. With
`sold_at` (comma-separated): only products sold at one of those sales points (phase 3S; the
waiter app asks for in_store,in_store_takeaway)."""
from sqlalchemy.orm import selectinload
q = db.query(Product).options(selectinload(Product.memberships), selectinload(Product.prep_zones))
has_dashboard = holds(user, "core.dashboard.access")
@@ -277,8 +280,15 @@ def list_products(all: bool = False, category_id: int | None = None, db: Session
q = q.join(ProductCategory, ProductCategory.product_id == Product.id) \
.filter(ProductCategory.category_id == category_id) \
.order_by(ProductCategory.sort_order, Product.id)
return q.all()
return q.order_by(Product.sort_order, Product.id).all()
return _sold_filter(q.all(), sold_at)
return _sold_filter(q.order_by(Product.sort_order, Product.id).all(), sold_at)
def _sold_filter(products, points):
"""`points`: sales points, comma-separated; a product sold at any of them stays."""
from core.sales_points import normalize, sold_at
wanted = set(normalize((points or "").split(",")))
return products if not points else [p for p in products if wanted & set(sold_at(p))]
def _apply_categories(db, product, body, creating: bool) -> None:
@@ -336,6 +346,7 @@ def create_product(body: ProductCreate, db: Session = Depends(get_db), user: Use
if body.cost_breakdown is not None:
data["cost_breakdown"] = json.dumps([item.model_dump() for item in body.cost_breakdown])
data["tags"] = json.dumps(body.tags) if body.tags is not None else None
data["sold_at"] = sales_points.dump(body.sold_at)
product = Product(**data)
db.add(product)
db.flush()
@@ -393,7 +404,7 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
"category_id", "primary_category_id", "category_ids"},
)
for field, value in scalar_fields.items():
setattr(product, field, value)
setattr(product, field, sales_points.dump(value) if field == "sold_at" else value)
_apply_categories(db, product, body, creating=False)
# Update prep zones if provided
if body.prep_zone_ids is not None: