Files
orion/app/modules/loyalty/schemas/stamp.py
Samir Boulahtit d8f3338bc8 feat(loyalty): implement Phase 2 - company-wide points system
Complete implementation of loyalty module Phase 2 features:

Database & Models:
- Add company_id to LoyaltyProgram for chain-wide loyalty
- Add company_id to LoyaltyCard for multi-location support
- Add CompanyLoyaltySettings model for admin-controlled settings
- Add points expiration, welcome bonus, and minimum redemption fields
- Add POINTS_EXPIRED, WELCOME_BONUS transaction types

Services:
- Update program_service for company-based queries
- Update card_service with enrollment and welcome bonus
- Update points_service with void_points for returns
- Update stamp_service for company context
- Update pin_service for company-wide operations

API Endpoints:
- Admin: Program listing with stats, company detail views
- Vendor: Terminal operations, card management, settings
- Storefront: Customer card/transactions, self-enrollment

UI Templates:
- Admin: Programs dashboard, company detail, settings
- Vendor: Terminal, cards list, card detail, settings, stats, enrollment
- Storefront: Dashboard, history, enrollment, success pages

Background Tasks:
- Point expiration task (daily, based on inactivity)
- Wallet sync task (hourly)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 22:10:27 +01:00

187 lines
4.1 KiB
Python

# app/modules/loyalty/schemas/stamp.py
"""
Pydantic schemas for stamp operations.
Company-based stamps:
- Stamps earned at any vendor count toward company total
- Stamps can be redeemed at any vendor within the company
- Supports voiding stamps for returns
"""
from datetime import datetime
from pydantic import BaseModel, Field
class StampRequest(BaseModel):
"""Schema for adding a stamp to a card."""
card_id: int | None = Field(
None,
description="Card ID (use this or qr_code)",
)
qr_code: str | None = Field(
None,
description="QR code data from card scan",
)
card_number: str | None = Field(
None,
description="Card number (manual entry)",
)
# Authentication
staff_pin: str | None = Field(
None,
min_length=4,
max_length=6,
description="Staff PIN for verification",
)
# Optional metadata
notes: str | None = Field(
None,
max_length=500,
description="Optional note about this stamp",
)
class StampResponse(BaseModel):
"""Schema for stamp operation response."""
success: bool = True
message: str = "Stamp added successfully"
# Card state after stamp
card_id: int
card_number: str
stamp_count: int
stamps_target: int
stamps_until_reward: int
# Did this trigger a reward?
reward_earned: bool = False
reward_description: str | None = None
# Cooldown info
next_stamp_available_at: datetime | None = None
# Today's activity
stamps_today: int
stamps_remaining_today: int
# Location
vendor_id: int | None = None
class StampRedeemRequest(BaseModel):
"""Schema for redeeming stamps for a reward."""
card_id: int | None = Field(
None,
description="Card ID (use this or qr_code)",
)
qr_code: str | None = Field(
None,
description="QR code data from card scan",
)
card_number: str | None = Field(
None,
description="Card number (manual entry)",
)
# Authentication
staff_pin: str | None = Field(
None,
min_length=4,
max_length=6,
description="Staff PIN for verification",
)
# Optional metadata
notes: str | None = Field(
None,
max_length=500,
description="Optional note about this redemption",
)
class StampRedeemResponse(BaseModel):
"""Schema for stamp redemption response."""
success: bool = True
message: str = "Reward redeemed successfully"
# Card state after redemption
card_id: int
card_number: str
stamp_count: int # Should be 0 after redemption
stamps_target: int
# Reward info
reward_description: str
total_redemptions: int # Lifetime redemptions for this card
# Location
vendor_id: int | None = None
class StampVoidRequest(BaseModel):
"""Schema for voiding stamps (for returns)."""
card_id: int | None = Field(
None,
description="Card ID (use this or qr_code)",
)
qr_code: str | None = Field(
None,
description="QR code data from card scan",
)
card_number: str | None = Field(
None,
description="Card number (manual entry)",
)
# Stamps to void (use one method)
stamps_to_void: int | None = Field(
None,
gt=0,
description="Number of stamps to void",
)
original_transaction_id: int | None = Field(
None,
description="ID of original transaction to void",
)
# Authentication
staff_pin: str | None = Field(
None,
min_length=4,
max_length=6,
description="Staff PIN for verification",
)
# Required metadata
notes: str | None = Field(
None,
max_length=500,
description="Reason for voiding",
)
class StampVoidResponse(BaseModel):
"""Schema for stamp void response."""
success: bool = True
message: str = "Stamps voided successfully"
# Void info
stamps_voided: int
# Card state after void
card_id: int
card_number: str
stamp_count: int
# Location
vendor_id: int | None = None