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:
@@ -59,7 +59,7 @@ import models.recovery_code # noqa: F401
|
||||
|
||||
from models.user import User, WaiterZone
|
||||
from models.table import TableGroup, Table
|
||||
from models.product import Category, Product
|
||||
from models.product import Category, Product, ProductCategory
|
||||
from models.order import Order, OrderItem, OrderWaiter, OrderAuditLog
|
||||
from models.business_day import BusinessDay
|
||||
from models.shift import WaiterShift
|
||||
@@ -282,17 +282,18 @@ try:
|
||||
|
||||
cat_products = []
|
||||
for prod_sort, (prod_name, prod_price, prod_cost) in enumerate(items):
|
||||
p = db.query(Product).filter(Product.name == prod_name, Product.category_id == cat.id).first()
|
||||
p = db.query(Product).filter(Product.name == prod_name, Product.primary_category_id == cat.id).first()
|
||||
if not p:
|
||||
p = Product(
|
||||
name=prod_name,
|
||||
category_id=cat.id,
|
||||
primary_category_id=cat.id,
|
||||
base_price=prod_price,
|
||||
cost_simple=prod_cost,
|
||||
is_available=True,
|
||||
lifecycle_status="active",
|
||||
sort_order=prod_sort,
|
||||
)
|
||||
p.memberships.append(ProductCategory(category_id=cat.id, sort_order=prod_sort))
|
||||
db.add(p)
|
||||
db.flush()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user