fix(loyalty): translate category names in transaction history
Some checks failed
CI / ruff (push) Successful in 15s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has been cancelled

Category names in transaction tables now resolve to the current
page language instead of always showing English. Updated:
- category_service.validate_category_for_store: accepts lang param,
  uses get_translated_name()
- Store transactions list route: passes request.state.language
- Card detail transactions route: passes request.state.language
- card_service.get_customer_transactions_with_store_names: accepts
  lang param for storefront route

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 14:17:43 +02:00
parent 10e37e749b
commit 255ac6525e
3 changed files with 29 additions and 9 deletions

View File

@@ -807,6 +807,7 @@ class CardService:
*,
skip: int = 0,
limit: int = 20,
lang: str = "en",
) -> tuple[list[dict], int]:
"""
Get transaction history for a card with store names resolved.
@@ -853,7 +854,7 @@ class CardService:
names = []
for cid in tx.category_ids:
name = category_service.validate_category_for_store(
db, cid, tx.store_id or 0
db, cid, tx.store_id or 0, lang=lang
)
if name:
names.append(name)

View File

@@ -138,11 +138,11 @@ class CategoryService:
logger.info(f"Deleted category {category_id} from store {store_id}")
def validate_category_for_store(
self, db: Session, category_id: int, store_id: int
self, db: Session, category_id: int, store_id: int, lang: str = "en"
) -> str | None:
"""Validate that a category belongs to the store.
Returns the category name if valid, None if not found.
Returns the translated category name if valid, None if not found.
"""
category = (
db.query(StoreTransactionCategory)
@@ -153,7 +153,9 @@ class CategoryService:
)
.first()
)
return category.name if category else None
if not category:
return None
return category.get_translated_name(lang)
# Singleton