Improve public pages
This commit is contained in:
102
services/tenant/scripts/seed_pilot_coupon.py
Normal file
102
services/tenant/scripts/seed_pilot_coupon.py
Normal file
@@ -0,0 +1,102 @@
|
||||
"""
|
||||
Seed script to create the PILOT2025 coupon for the pilot customer program.
|
||||
This coupon provides 3 months (90 days) free trial extension for the first 20 customers.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import uuid
|
||||
|
||||
# Add project root to path
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')))
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models.coupon import CouponModel
|
||||
from shared.database import get_db
|
||||
|
||||
|
||||
def seed_pilot_coupon(db: Session):
|
||||
"""Create or update the PILOT2025 coupon"""
|
||||
|
||||
coupon_code = "PILOT2025"
|
||||
|
||||
# Check if coupon already exists
|
||||
existing_coupon = db.query(CouponModel).filter(
|
||||
CouponModel.code == coupon_code
|
||||
).first()
|
||||
|
||||
if existing_coupon:
|
||||
print(f"✓ Coupon {coupon_code} already exists")
|
||||
print(f" Current redemptions: {existing_coupon.current_redemptions}/{existing_coupon.max_redemptions}")
|
||||
print(f" Active: {existing_coupon.active}")
|
||||
print(f" Valid from: {existing_coupon.valid_from}")
|
||||
print(f" Valid until: {existing_coupon.valid_until}")
|
||||
return existing_coupon
|
||||
|
||||
# Create new coupon
|
||||
now = datetime.utcnow()
|
||||
valid_until = now + timedelta(days=180) # Valid for 6 months
|
||||
|
||||
coupon = CouponModel(
|
||||
id=uuid.uuid4(),
|
||||
code=coupon_code,
|
||||
discount_type="trial_extension",
|
||||
discount_value=90, # 90 days = 3 months
|
||||
max_redemptions=20, # First 20 pilot customers
|
||||
current_redemptions=0,
|
||||
valid_from=now,
|
||||
valid_until=valid_until,
|
||||
active=True,
|
||||
created_at=now,
|
||||
extra_data={
|
||||
"program": "pilot_launch_2025",
|
||||
"description": "Programa piloto - 3 meses gratis para los primeros 20 clientes",
|
||||
"terms": "Válido para nuevos registros únicamente. Un cupón por cliente."
|
||||
}
|
||||
)
|
||||
|
||||
db.add(coupon)
|
||||
db.commit()
|
||||
db.refresh(coupon)
|
||||
|
||||
print(f"✓ Successfully created coupon: {coupon_code}")
|
||||
print(f" Type: Trial Extension")
|
||||
print(f" Value: 90 days (3 months)")
|
||||
print(f" Max redemptions: 20")
|
||||
print(f" Valid from: {coupon.valid_from}")
|
||||
print(f" Valid until: {coupon.valid_until}")
|
||||
print(f" ID: {coupon.id}")
|
||||
|
||||
return coupon
|
||||
|
||||
|
||||
def main():
|
||||
"""Main execution function"""
|
||||
print("=" * 60)
|
||||
print("Seeding PILOT2025 Coupon for Pilot Customer Program")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
try:
|
||||
# Get database session
|
||||
db = next(get_db())
|
||||
|
||||
# Seed the coupon
|
||||
seed_pilot_coupon(db)
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("✓ Coupon seeding completed successfully!")
|
||||
print("=" * 60)
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ Error seeding coupon: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user