feat(loyalty): translatable categories + mandatory on earn points
Some checks failed
CI / pytest (push) Failing after 2h47m45s
CI / validate (push) Successful in 39s
CI / dependency-scanning (push) Successful in 47s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped
CI / ruff (push) Successful in 21s

- Add name_translations JSON column to StoreTransactionCategory
  (migration loyalty_008). Stores {"en": "Men", "fr": "Hommes", ...}.
  Model has get_translated_name(lang) helper.
- Admin CRUD form now has FR/DE/LB translation inputs alongside the
  default name.
- Points earn: category_id is now mandatory when the store has
  active categories configured. Returns CATEGORY_REQUIRED error.
- Stamps: category remains optional (quick tap workflow).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-19 14:12:55 +02:00
parent ab2daf99bd
commit eafa086c73
6 changed files with 101 additions and 9 deletions

View File

@@ -23,6 +23,7 @@ from app.modules.loyalty.exceptions import (
InsufficientPointsException,
InvalidRewardException,
LoyaltyCardInactiveException,
LoyaltyException,
LoyaltyProgramInactiveException,
OrderReferenceRequiredException,
StaffPinRequiredException,
@@ -102,6 +103,19 @@ class PointsService:
if settings and settings.require_order_reference and not order_reference:
raise OrderReferenceRequiredException()
# Category is mandatory when the store has categories configured
if not category_id:
from app.modules.loyalty.services.category_service import category_service
store_categories = category_service.list_categories(
db, store_id, active_only=True
)
if store_categories:
raise LoyaltyException(
message="Please select a product category",
error_code="CATEGORY_REQUIRED",
)
# Idempotency guard: if same order_reference already earned points on this card, return existing result
if order_reference:
existing_tx = (