feat(loyalty): transaction categories (what was sold)
Some checks failed
Some checks failed
Merchants can configure per-store product categories (e.g., Men,
Women, Accessories, Kids) that sellers select when entering loyalty
transactions. Enables per-category sales analytics.
Backend:
- New model: StoreTransactionCategory (store-scoped, max 10 per store)
- Migration loyalty_007: creates table + adds category_id FK on
loyalty_transactions
- New category_service.py with CRUD + validation
- New schemas/category.py (Create, Update, Response, ListResponse)
- Admin CRUD: GET/POST/PATCH/DELETE /admin/loyalty/stores/{id}/categories
- Store CRUD: GET/POST/PATCH/DELETE /store/loyalty/categories
- Stamp/Points request schemas accept optional category_id
- Stamp/Points services pass category_id to transaction creation
- TransactionResponse includes category_id + category_name
342 tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -188,6 +188,8 @@ class TransactionResponse(BaseModel):
|
||||
order_reference: str | None = None
|
||||
reward_id: str | None = None
|
||||
reward_description: str | None = None
|
||||
category_id: int | None = None
|
||||
category_name: str | None = None
|
||||
notes: str | None = None
|
||||
|
||||
# Customer
|
||||
|
||||
42
app/modules/loyalty/schemas/category.py
Normal file
42
app/modules/loyalty/schemas/category.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# app/modules/loyalty/schemas/category.py
|
||||
"""Pydantic schemas for transaction categories."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CategoryCreate(BaseModel):
|
||||
"""Schema for creating a transaction category."""
|
||||
|
||||
name: str = Field(..., min_length=1, max_length=100)
|
||||
display_order: int = Field(default=0, ge=0)
|
||||
|
||||
|
||||
class CategoryUpdate(BaseModel):
|
||||
"""Schema for updating a transaction category."""
|
||||
|
||||
name: str | None = Field(None, min_length=1, max_length=100)
|
||||
display_order: int | None = Field(None, ge=0)
|
||||
is_active: bool | None = None
|
||||
|
||||
|
||||
class CategoryResponse(BaseModel):
|
||||
"""Schema for transaction category response."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
store_id: int
|
||||
name: str
|
||||
display_order: int
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class CategoryListResponse(BaseModel):
|
||||
"""Schema for listing categories."""
|
||||
|
||||
categories: list[CategoryResponse]
|
||||
total: int
|
||||
@@ -47,6 +47,12 @@ class PointsEarnRequest(BaseModel):
|
||||
description="Staff PIN for verification",
|
||||
)
|
||||
|
||||
# Category (what was sold)
|
||||
category_id: int | None = Field(
|
||||
None,
|
||||
description="Transaction category ID (e.g., Men, Women, Accessories)",
|
||||
)
|
||||
|
||||
# Optional metadata
|
||||
notes: str | None = Field(
|
||||
None,
|
||||
|
||||
@@ -37,6 +37,12 @@ class StampRequest(BaseModel):
|
||||
description="Staff PIN for verification",
|
||||
)
|
||||
|
||||
# Category (what was sold)
|
||||
category_id: int | None = Field(
|
||||
None,
|
||||
description="Transaction category ID (e.g., Men, Women, Accessories)",
|
||||
)
|
||||
|
||||
# Optional metadata
|
||||
notes: str | None = Field(
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user