fix(loyalty): fix runtime bugs in storefront routes, point expiration, and enforce settings
- Add total_points_voided column to LoyaltyCard with migration (loyalty_002) - Fix storefront self_enroll to use correct service method signature and schema fields - Fix get_my_card/get_my_transactions to use get_card_by_customer_and_merchant - Fix transaction history field reference (balance_after -> points_balance_after) - Fix point_expiration task: wrong field names and manual balance update -> card.expire_points() - Register storefront_router in definition.py and export all routers from __init__.py - Enforce MerchantLoyaltySettings in storefront enrollment, points, and stamp void operations - Fix test fixture using non-existent balance_after column - Suppress intentional architecture validator warnings in templates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -160,6 +160,12 @@ class LoyaltyCard(Base, TimestampMixin):
|
||||
nullable=False,
|
||||
comment="Lifetime points redeemed",
|
||||
)
|
||||
total_points_voided = Column(
|
||||
Integer,
|
||||
default=0,
|
||||
nullable=False,
|
||||
comment="Lifetime points voided (returns + expirations)",
|
||||
)
|
||||
|
||||
# =========================================================================
|
||||
# Wallet Integration
|
||||
@@ -326,6 +332,7 @@ class LoyaltyCard(Base, TimestampMixin):
|
||||
points: Number of points to void
|
||||
"""
|
||||
self.points_balance = max(0, self.points_balance - points)
|
||||
self.total_points_voided += points
|
||||
self.last_activity_at = datetime.now(UTC)
|
||||
|
||||
def expire_points(self, points: int) -> None:
|
||||
@@ -336,6 +343,7 @@ class LoyaltyCard(Base, TimestampMixin):
|
||||
points: Number of points to expire
|
||||
"""
|
||||
self.points_balance = max(0, self.points_balance - points)
|
||||
self.total_points_voided += points
|
||||
|
||||
# =========================================================================
|
||||
# Properties
|
||||
|
||||
Reference in New Issue
Block a user