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:
@@ -74,6 +74,7 @@ CODES: dict[str, tuple[int, str]] = {
|
||||
"pos.table_not_yours": (403, "{table} isn't in your zones. A manager can add the zone to your account."),
|
||||
"pos.items_changed": (409, "Some of these items were paid or cancelled in the meantime. Check the order and try again."),
|
||||
"pos.order_unpaid": (409, "Items still unpaid: {count}. Take the payment or cancel them first."),
|
||||
"order.not_sold_here": (422, "{name} isn't sold for this kind of order."),
|
||||
"refund.invalid": (422, "This refund doesn't add up ({reason})."),
|
||||
"refund.too_old": (409, "Only payments from today's business day can be refunded at the counter."),
|
||||
"refund.items_changed": (409, "Some of these items were refunded in the meantime. Check the order and try again."),
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
"""Sales points (plan phase 3S, step S.1): where an order is sold. A fixed list in code.
|
||||
|
||||
Every order records its sales point (`orders.sales_point`); a product says where it's sold
|
||||
(`products.sold_at`); prices for a sales point are price modifiers with the condition
|
||||
`order_channel` (its `channels` param holds sales points). Labels live in the i18n packages
|
||||
(`common:salesPoints.<key>`).
|
||||
|
||||
in_store the counter and the waiters, eating in
|
||||
in_store_takeaway the counter, to take away (and phone orders delivered by the venue)
|
||||
qr_table the QR menu, ordering at the table
|
||||
online_takeaway online ordering, collected at the venue
|
||||
online_delivery online ordering, delivered
|
||||
online_preorder online reservation with food ready on arrival
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
IN_STORE = "in_store"
|
||||
IN_STORE_TAKEAWAY = "in_store_takeaway"
|
||||
QR_TABLE = "qr_table"
|
||||
ONLINE_TAKEAWAY = "online_takeaway"
|
||||
ONLINE_DELIVERY = "online_delivery"
|
||||
ONLINE_PREORDER = "online_preorder"
|
||||
|
||||
ALL: tuple[str, ...] = (IN_STORE, IN_STORE_TAKEAWAY, QR_TABLE, ONLINE_TAKEAWAY, ONLINE_DELIVERY, ONLINE_PREORDER)
|
||||
IN_PERSON: tuple[str, ...] = (IN_STORE, IN_STORE_TAKEAWAY)
|
||||
ONLINE: tuple[str, ...] = (ONLINE_TAKEAWAY, ONLINE_DELIVERY, ONLINE_PREORDER)
|
||||
DIGITAL: tuple[str, ...] = (QR_TABLE,) + ONLINE # what the cloud's customer apps sell
|
||||
|
||||
# the order_channel condition's values before S.1 → sales points
|
||||
LEGACY_CHANNELS: dict[str, tuple[str, ...]] = {
|
||||
"pos": (IN_STORE,),
|
||||
"takeaway": (IN_STORE_TAKEAWAY,),
|
||||
"online": ONLINE,
|
||||
"qr": (QR_TABLE,),
|
||||
}
|
||||
|
||||
|
||||
def normalize(values) -> list[str]:
|
||||
"""Sales points from a list that may hold old channel names; unknown values dropped,
|
||||
order kept, no duplicates."""
|
||||
out: list[str] = []
|
||||
for v in values or []:
|
||||
for sp in (v,) if v in ALL else LEGACY_CHANNELS.get(v, ()):
|
||||
if sp not in out:
|
||||
out.append(sp)
|
||||
return out
|
||||
|
||||
|
||||
def for_order(order_type: str | None, source: str | None = None, online_order_type: str | None = None) -> str:
|
||||
"""The sales point of an order from what older code records (type, source)."""
|
||||
if source == "online":
|
||||
if online_order_type == "delivery":
|
||||
return ONLINE_DELIVERY
|
||||
if online_order_type == "takeaway":
|
||||
return ONLINE_TAKEAWAY
|
||||
if online_order_type == "preorder":
|
||||
return ONLINE_PREORDER
|
||||
return QR_TABLE # the QR menu's table orders arrive as online "dine_in"
|
||||
return IN_STORE_TAKEAWAY if order_type in ("takeaway", "delivery") else IN_STORE
|
||||
|
||||
|
||||
def of_order(order) -> str:
|
||||
return getattr(order, "sales_point", None) or for_order(order.order_type, order.source, order.online_order_type)
|
||||
|
||||
|
||||
def sold_at(product) -> list[str]:
|
||||
"""Where a product is sold (`products.sold_at`, JSON); missing or unreadable = everywhere."""
|
||||
raw = getattr(product, "sold_at", None)
|
||||
if raw is None:
|
||||
return list(ALL)
|
||||
try:
|
||||
values = json.loads(raw) if isinstance(raw, str) else raw
|
||||
except ValueError:
|
||||
return list(ALL)
|
||||
return normalize(values)
|
||||
|
||||
|
||||
def is_sold_at(product, point: str) -> bool:
|
||||
return point in sold_at(product)
|
||||
|
||||
|
||||
def dump(values) -> str:
|
||||
"""For `products.sold_at`: the sales points in the fixed order."""
|
||||
chosen = set(normalize(values))
|
||||
return json.dumps([sp for sp in ALL if sp in chosen])
|
||||
Reference in New Issue
Block a user