update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
# Add parent directory to path to import from src
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -150,34 +151,96 @@ def seed_homepage_content(db: Session):
|
||||
trust_badges_section_subtitle = 'Awards and certifications that validate our commitment to excellence'
|
||||
trust_badges_enabled = True
|
||||
|
||||
# Promotions
|
||||
# Promotions - Mix of valid and expired for testing
|
||||
# Calculate dates relative to current date
|
||||
today = datetime.now()
|
||||
next_month = today + timedelta(days=30)
|
||||
next_3_months = today + timedelta(days=90)
|
||||
next_6_months = today + timedelta(days=180)
|
||||
expired_1_month_ago = today - timedelta(days=30)
|
||||
expired_3_months_ago = today - timedelta(days=90)
|
||||
|
||||
promotions = [
|
||||
{
|
||||
'title': 'Early Bird Special',
|
||||
'description': 'Book 30 days in advance and save 20% on your stay. Perfect for planning ahead!',
|
||||
'image': 'https://images.unsplash.com/photo-1564501049412-61c2a3083791?w=600',
|
||||
'discount': '20% OFF',
|
||||
'valid_until': next_3_months.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Book Now',
|
||||
'code': 'EARLYBIRD20'
|
||||
},
|
||||
{
|
||||
'title': 'Weekend Getaway',
|
||||
'description': 'Perfect weekend escape with complimentary breakfast and spa access. Relax and unwind!',
|
||||
'image': 'https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=600',
|
||||
'discount': '30% OFF',
|
||||
'valid_until': next_month.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'View Offer',
|
||||
'code': 'WEEKEND30'
|
||||
},
|
||||
{
|
||||
'title': 'Luxury Suite Package',
|
||||
'description': 'Experience our premium suites with exclusive amenities, fine dining, and concierge service',
|
||||
'image': 'https://images.unsplash.com/photo-1582719478250-c89cae4dc85b?w=600',
|
||||
'discount': 'Save $200',
|
||||
'valid_until': next_6_months.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Explore Suites',
|
||||
'code': 'LUXURY200'
|
||||
},
|
||||
{
|
||||
'title': 'Honeymoon Special',
|
||||
'description': 'Romantic getaway with champagne, flowers, special amenities, and complimentary room upgrade',
|
||||
'image': 'https://images.unsplash.com/photo-1596394516093-501ba68a0ba6?w=600',
|
||||
'discount': '25% OFF',
|
||||
'valid_until': next_3_months.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Book Package',
|
||||
'code': 'HONEYMOON25'
|
||||
},
|
||||
{
|
||||
'title': 'Family Fun Package',
|
||||
'description': 'Perfect for families! Includes family room, kids activities, and complimentary meals for children under 12',
|
||||
'image': 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=600',
|
||||
'discount': '15% OFF',
|
||||
'valid_until': next_6_months.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Book Now',
|
||||
'code': 'FAMILY15'
|
||||
},
|
||||
{
|
||||
'title': 'Business Traveler',
|
||||
'description': 'Extended stay discounts for business travelers. Includes high-speed WiFi, workspace, and airport transfer',
|
||||
'image': 'https://images.unsplash.com/photo-1551882547-ff40c63fe5fa?w=600',
|
||||
'discount': '10% OFF',
|
||||
'valid_until': next_3_months.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Learn More',
|
||||
'code': 'BUSINESS10'
|
||||
},
|
||||
# Expired promotions for testing display logic
|
||||
{
|
||||
'title': 'Summer Special',
|
||||
'description': 'Enjoy 25% off on all room bookings this summer. Limited time offer!',
|
||||
'image': 'https://images.unsplash.com/photo-1564501049412-61c2a3083791?w=600',
|
||||
'discount': '25% OFF',
|
||||
'valid_until': '2024-08-31',
|
||||
'valid_until': expired_3_months_ago.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Book Now'
|
||||
'button_text': 'Book Now',
|
||||
'code': 'SUMMER25'
|
||||
},
|
||||
{
|
||||
'title': 'Weekend Getaway',
|
||||
'description': 'Perfect weekend escape with complimentary breakfast and spa access',
|
||||
'image': 'https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=600',
|
||||
'discount': '30% OFF',
|
||||
'valid_until': '2024-12-31',
|
||||
'title': 'New Year Celebration',
|
||||
'description': 'Ring in the new year with our special celebration package. Includes party access and premium amenities',
|
||||
'image': 'https://images.unsplash.com/photo-1590490360182-c33d57733427?w=600',
|
||||
'discount': '35% OFF',
|
||||
'valid_until': expired_1_month_ago.strftime('%Y-%m-%d'),
|
||||
'link': '/rooms',
|
||||
'button_text': 'Learn More'
|
||||
},
|
||||
{
|
||||
'title': 'Honeymoon Package',
|
||||
'description': 'Romantic getaway with champagne, flowers, and special amenities',
|
||||
'image': 'https://images.unsplash.com/photo-1582719478250-c89cae4dc85b?w=600',
|
||||
'discount': 'Special Rate',
|
||||
'valid_until': '2024-12-31',
|
||||
'link': '/rooms',
|
||||
'button_text': 'Book Package'
|
||||
'button_text': 'View Offer',
|
||||
'code': 'NEWYEAR35'
|
||||
}
|
||||
]
|
||||
promotions_section_title = 'Special Offers'
|
||||
|
||||
157
Backend/seeds_data/seed_promotions.py
Normal file
157
Backend/seeds_data/seed_promotions.py
Normal file
@@ -0,0 +1,157 @@
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
# Add parent directory to path to import from src
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from sqlalchemy.orm import Session
|
||||
from src.shared.config.database import SessionLocal
|
||||
from src.loyalty.models.promotion import Promotion, DiscountType
|
||||
|
||||
def seed_promotions(db: Session):
|
||||
"""Seed promotions that match the homepage promotion codes"""
|
||||
|
||||
# Calculate dates relative to current UTC date
|
||||
# Use UTC consistently to match validation logic
|
||||
now = datetime.utcnow()
|
||||
|
||||
# Start date: Start of today (00:00:00) to ensure promotion is immediately active
|
||||
start_date = datetime(now.year, now.month, now.day, 0, 0, 0)
|
||||
|
||||
# End dates: future dates at end of day (23:59:59)
|
||||
next_month_date = now + timedelta(days=30)
|
||||
next_month = datetime(next_month_date.year, next_month_date.month, next_month_date.day, 23, 59, 59)
|
||||
|
||||
next_3_months_date = now + timedelta(days=90)
|
||||
next_3_months = datetime(next_3_months_date.year, next_3_months_date.month, next_3_months_date.day, 23, 59, 59)
|
||||
|
||||
next_6_months_date = now + timedelta(days=180)
|
||||
next_6_months = datetime(next_6_months_date.year, next_6_months_date.month, next_6_months_date.day, 23, 59, 59)
|
||||
|
||||
promotions_data = [
|
||||
{
|
||||
'code': 'EARLYBIRD20',
|
||||
'name': 'Early Bird Special',
|
||||
'description': 'Book 30 days in advance and save 20% on your stay. Perfect for planning ahead!',
|
||||
'discount_type': DiscountType.percentage,
|
||||
'discount_value': 20.00,
|
||||
'start_date': start_date,
|
||||
'end_date': next_3_months,
|
||||
'is_active': True,
|
||||
'min_booking_amount': None,
|
||||
'max_discount_amount': None,
|
||||
'usage_limit': None,
|
||||
},
|
||||
{
|
||||
'code': 'WEEKEND30',
|
||||
'name': 'Weekend Getaway',
|
||||
'description': 'Perfect weekend escape with complimentary breakfast and spa access. Relax and unwind!',
|
||||
'discount_type': DiscountType.percentage,
|
||||
'discount_value': 30.00,
|
||||
'start_date': start_date,
|
||||
'end_date': next_month,
|
||||
'is_active': True,
|
||||
'min_booking_amount': None,
|
||||
'max_discount_amount': None,
|
||||
'usage_limit': None,
|
||||
},
|
||||
{
|
||||
'code': 'LUXURY200',
|
||||
'name': 'Luxury Suite Package',
|
||||
'description': 'Experience our premium suites with exclusive amenities, fine dining, and concierge service',
|
||||
'discount_type': DiscountType.fixed_amount,
|
||||
'discount_value': 200.00,
|
||||
'start_date': start_date,
|
||||
'end_date': next_6_months,
|
||||
'is_active': True,
|
||||
'min_booking_amount': None, # No minimum for now
|
||||
'max_discount_amount': None,
|
||||
'usage_limit': None,
|
||||
},
|
||||
{
|
||||
'code': 'HONEYMOON25',
|
||||
'name': 'Honeymoon Special',
|
||||
'description': 'Romantic getaway with champagne, flowers, special amenities, and complimentary room upgrade',
|
||||
'discount_type': DiscountType.percentage,
|
||||
'discount_value': 25.00,
|
||||
'start_date': start_date,
|
||||
'end_date': next_3_months,
|
||||
'is_active': True,
|
||||
'min_booking_amount': None,
|
||||
'max_discount_amount': None,
|
||||
'usage_limit': None,
|
||||
},
|
||||
{
|
||||
'code': 'FAMILY15',
|
||||
'name': 'Family Fun Package',
|
||||
'description': 'Perfect for families! Includes family room, kids activities, and complimentary meals for children under 12',
|
||||
'discount_type': DiscountType.percentage,
|
||||
'discount_value': 15.00,
|
||||
'start_date': start_date,
|
||||
'end_date': next_6_months,
|
||||
'is_active': True,
|
||||
'min_booking_amount': None,
|
||||
'max_discount_amount': None,
|
||||
'usage_limit': None,
|
||||
},
|
||||
{
|
||||
'code': 'BUSINESS10',
|
||||
'name': 'Business Traveler',
|
||||
'description': 'Extended stay discounts for business travelers. Includes high-speed WiFi, workspace, and airport transfer',
|
||||
'discount_type': DiscountType.percentage,
|
||||
'discount_value': 10.00,
|
||||
'start_date': start_date,
|
||||
'end_date': next_3_months,
|
||||
'is_active': True,
|
||||
'min_booking_amount': None,
|
||||
'max_discount_amount': None,
|
||||
'usage_limit': None,
|
||||
},
|
||||
]
|
||||
|
||||
created_count = 0
|
||||
updated_count = 0
|
||||
|
||||
for promo_data in promotions_data:
|
||||
existing = db.query(Promotion).filter(Promotion.code == promo_data['code']).first()
|
||||
|
||||
if existing:
|
||||
# Update existing promotion
|
||||
for key, value in promo_data.items():
|
||||
if key != 'code': # Don't update the code
|
||||
setattr(existing, key, value)
|
||||
existing.updated_at = datetime.utcnow()
|
||||
updated_count += 1
|
||||
print(f'✓ Updated promotion: {promo_data["code"]}')
|
||||
else:
|
||||
# Create new promotion
|
||||
promotion = Promotion(**promo_data)
|
||||
db.add(promotion)
|
||||
created_count += 1
|
||||
print(f'✓ Created promotion: {promo_data["code"]}')
|
||||
|
||||
db.commit()
|
||||
print(f'\n✓ Promotions seeded: {created_count} created, {updated_count} updated')
|
||||
|
||||
def main():
|
||||
db: Session = SessionLocal()
|
||||
try:
|
||||
print('=' * 80)
|
||||
print('SEEDING PROMOTIONS')
|
||||
print('=' * 80)
|
||||
print()
|
||||
seed_promotions(db)
|
||||
print('\n' + '=' * 80)
|
||||
print('✓ All promotions seeded successfully!')
|
||||
print('=' * 80)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f'\n✗ Error seeding promotions: {e}')
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
raise
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user