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:
2026-11-13 12:39:02 +02:00
parent 3c5751025c
commit 6d42be95f8
20 changed files with 445 additions and 56 deletions
+19 -2
View File
@@ -311,7 +311,12 @@ class CostBreakdownItem(BaseModel):
class ProductBase(BaseModel):
name: str
description: Optional[str] = None
# D-23: listed in category_ids (primary first in output); primary_category_id decides
# tickets/reports. category_id is DEV SCAFFOLDING (§3.3) for the current manager and
# waiter screens: in output = the primary; as input = "move the product's primary to".
category_id: Optional[int] = None
primary_category_id: Optional[int] = None
category_ids: Optional[List[int]] = None
base_price: float
# piece | portion | kg | liter | gram | ml
unit_type: str = "piece"
@@ -353,7 +358,9 @@ class ProductCreate(ProductBase):
class ProductUpdate(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
category_id: Optional[int] = None
category_id: Optional[int] = None # scaffolding, see ProductBase
primary_category_id: Optional[int] = None
category_ids: Optional[List[int]] = None # None = memberships unchanged
base_price: Optional[float] = None
unit_type: Optional[str] = None
is_available: Optional[bool] = None
@@ -390,10 +397,17 @@ class ProductUpdate(BaseModel):
class ProductReorderItem(BaseModel):
id: int
sort_order: int
category_id: Optional[int] = None # set: position within that category (D-23); unset: global order (v1)
class ProductCategoryOut(BaseModel):
category_id: int
sort_order: int
class ProductOut(ProductBase):
id: int
categories: List[ProductCategoryOut] = [] # every listing with its position in that category
quick_options: List[ProductQuickOptionOut] = []
options: List[ProductOptionOut] = []
ingredients: List[ProductIngredientOut] = []
@@ -419,7 +433,10 @@ class ProductOut(ProductBase):
'id': data.id,
'name': data.name,
'description': data.description,
'category_id': data.category_id,
'category_id': data.primary_category_id, # scaffolding (§3.3)
'primary_category_id': data.primary_category_id,
'category_ids': data.category_ids,
'categories': [{'category_id': m.category_id, 'sort_order': m.sort_order} for m in data.memberships],
'base_price': data.base_price,
'unit_type': getattr(data, 'unit_type', 'piece') or 'piece',
'is_available': data.is_available,