feat(backend): a product can be listed in several categories, with one primary category
Platform v2 step 1.13 (APPS_PLATFORM D-23).
- product_categories(product_id, category_id, sort_order); products.category_id becomes
products.primary_category_id (revision 0013 moves the data: one listing per product at its
old position). services/catalog.py keeps the rule "the primary is one of its categories"
and fixes up products when a category is deleted.
- Products API: category_ids + primary_category_id in and out, plus categories
[{category_id, sort_order}]; GET /api/products/?category_id= lists a category's products in
that category's order; PUT /reorder with category_id orders within a category. category_id
stays as dev scaffolding (section 3.3): output = primary, input = "move the primary".
- Primary category: ticket grouping and prep-zone category order, the order-item category
snapshot (1.12), report filters for waste-only rows and /meta/products.
- Every listing: price modifier / deal / min-quantity category targets, deal free choices,
the QR menu snapshot (product in each category it's listed in; images pushed once).
- Catalogue export v2: each category lists all its products with "primary" and
"category_sort_order"; import restores listings and order. v1 files are refused (D-21).
- New errors catalog.unknown_category, catalog.primary_not_listed.
This commit is contained in:
@@ -1060,12 +1060,12 @@ def product_performance(
|
||||
for pid, wdata in waste_by_product.items():
|
||||
if pid not in summary:
|
||||
product = products_db.get(pid)
|
||||
if category_id and (not product or product.category_id != category_id):
|
||||
if category_id and (not product or product.primary_category_id != category_id):
|
||||
continue
|
||||
summary[pid] = {
|
||||
"product_id": pid,
|
||||
"product_name": product.name if product else f"#{pid}",
|
||||
"category_id": product.category_id if product else None,
|
||||
"category_id": product.primary_category_id if product else None,
|
||||
"qty_sold": 0, "revenue": 0.0, "total_cost": 0.0, "trackable_profit": 0.0,
|
||||
"uncosted_revenue": 0.0, "uncosted_items": 0, "order_ids": set(),
|
||||
}
|
||||
@@ -1702,8 +1702,9 @@ def meta_products(
|
||||
{
|
||||
"id": p.id,
|
||||
"name": p.name,
|
||||
"category_id": p.category_id,
|
||||
"category_name": categories_db.get(p.category_id, "—"),
|
||||
"category_id": p.primary_category_id,
|
||||
"category_ids": p.category_ids, # every category it's listed in (D-23)
|
||||
"category_name": categories_db.get(p.primary_category_id, "—"),
|
||||
"price": float(p.base_price),
|
||||
}
|
||||
for p in products
|
||||
|
||||
Reference in New Issue
Block a user