updates
This commit is contained in:
Binary file not shown.
59
Backend/seeds_data/add_housekeeping_role.py
Normal file
59
Backend/seeds_data/add_housekeeping_role.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to add the 'housekeeping' role to the database.
|
||||
Run this script once to create the housekeeping role if it doesn't exist.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Add the Backend directory to the path
|
||||
backend_dir = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(backend_dir))
|
||||
|
||||
from src.shared.config.database import SessionLocal
|
||||
from src.models import Role # Use the models __init__ which handles all imports
|
||||
|
||||
def add_housekeeping_role():
|
||||
"""Add the housekeeping role to the database if it doesn't exist."""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
# Check if housekeeping role already exists
|
||||
existing_role = db.query(Role).filter(Role.name == 'housekeeping').first()
|
||||
|
||||
if existing_role:
|
||||
print("✓ Housekeeping role already exists in the database.")
|
||||
print(f" Role ID: {existing_role.id}")
|
||||
print(f" Role Name: {existing_role.name}")
|
||||
return
|
||||
|
||||
# Create the housekeeping role
|
||||
housekeeping_role = Role(
|
||||
name='housekeeping',
|
||||
description='Housekeeping staff role with access to room cleaning tasks and status updates'
|
||||
)
|
||||
db.add(housekeeping_role)
|
||||
db.commit()
|
||||
db.refresh(housekeeping_role)
|
||||
|
||||
print("✓ Housekeeping role created successfully!")
|
||||
print(f" Role ID: {housekeeping_role.id}")
|
||||
print(f" Role Name: {housekeeping_role.name}")
|
||||
print(f" Description: {housekeeping_role.description}")
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"✗ Error creating housekeeping role: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Adding housekeeping role to the database...")
|
||||
print("=" * 60)
|
||||
add_housekeeping_role()
|
||||
print("=" * 60)
|
||||
print("Done!")
|
||||
81
Backend/seeds_data/add_housekeeping_user.py
Normal file
81
Backend/seeds_data/add_housekeeping_user.py
Normal file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to add a housekeeping user to the database.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Add the Backend directory to the path
|
||||
backend_dir = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(backend_dir))
|
||||
|
||||
from src.shared.config.database import SessionLocal
|
||||
from src.models import Role, User
|
||||
import bcrypt
|
||||
|
||||
def add_housekeeping_user():
|
||||
"""Add the housekeeping user to the database if it doesn't exist."""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
# Get housekeeping role
|
||||
housekeeping_role = db.query(Role).filter(Role.name == 'housekeeping').first()
|
||||
|
||||
if not housekeeping_role:
|
||||
print("✗ Housekeeping role not found! Please run add_housekeeping_role.py first.")
|
||||
sys.exit(1)
|
||||
|
||||
# Check if user already exists
|
||||
existing_user = db.query(User).filter(User.email == 'housekeeping@gnxsoft.com').first()
|
||||
|
||||
if existing_user:
|
||||
print("✓ Housekeeping user already exists in the database.")
|
||||
print(f" User ID: {existing_user.id}")
|
||||
print(f" Email: {existing_user.email}")
|
||||
print(f" Full Name: {existing_user.full_name}")
|
||||
print(f" Role: {existing_user.role.name if existing_user.role else 'N/A'}")
|
||||
return
|
||||
|
||||
# Hash password
|
||||
password = 'P4eli240453.'
|
||||
password_bytes = password.encode('utf-8')
|
||||
salt = bcrypt.gensalt()
|
||||
hashed_password = bcrypt.hashpw(password_bytes, salt).decode('utf-8')
|
||||
|
||||
# Create the housekeeping user
|
||||
housekeeping_user = User(
|
||||
email='housekeeping@gnxsoft.com',
|
||||
password=hashed_password,
|
||||
full_name='Housekeeping Staff',
|
||||
role_id=housekeeping_role.id,
|
||||
is_active=True,
|
||||
currency='EUR'
|
||||
)
|
||||
db.add(housekeeping_user)
|
||||
db.commit()
|
||||
db.refresh(housekeeping_user)
|
||||
|
||||
print("✓ Housekeeping user created successfully!")
|
||||
print(f" User ID: {housekeeping_user.id}")
|
||||
print(f" Email: {housekeeping_user.email}")
|
||||
print(f" Full Name: {housekeeping_user.full_name}")
|
||||
print(f" Role: {housekeeping_role.name}")
|
||||
print(f" Password: P4eli240453.")
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"✗ Error creating housekeeping user: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Adding housekeeping user to the database...")
|
||||
print("=" * 60)
|
||||
add_housekeeping_user()
|
||||
print("=" * 60)
|
||||
print("Done!")
|
||||
|
||||
149
Backend/seeds_data/assign_housekeeping_tasks.py
Normal file
149
Backend/seeds_data/assign_housekeeping_tasks.py
Normal file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to assign test housekeeping tasks to the housekeeping user.
|
||||
This creates sample tasks for testing the housekeeping dashboard.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# Add the Backend directory to the path
|
||||
backend_dir = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(backend_dir))
|
||||
|
||||
from src.shared.config.database import SessionLocal
|
||||
from src.models import Role, User, Room
|
||||
from src.hotel_services.models.housekeeping_task import HousekeepingTask, HousekeepingStatus, HousekeepingType
|
||||
|
||||
def assign_housekeeping_tasks():
|
||||
"""Assign test housekeeping tasks to the housekeeping user."""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
# Get housekeeping user
|
||||
housekeeping_user = db.query(User).join(Role).filter(
|
||||
Role.name == 'housekeeping',
|
||||
User.email == 'housekeeping@gnxsoft.com'
|
||||
).first()
|
||||
|
||||
if not housekeeping_user:
|
||||
print("✗ Housekeeping user not found! Please run add_housekeeping_user.py first.")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"✓ Found housekeeping user: {housekeeping_user.email} (ID: {housekeeping_user.id})")
|
||||
|
||||
# Get admin user for created_by
|
||||
admin_role = db.query(Role).filter(Role.name == 'admin').first()
|
||||
admin_user = db.query(User).filter(User.role_id == admin_role.id).first() if admin_role else None
|
||||
|
||||
# Get some rooms
|
||||
rooms = db.query(Room).limit(5).all()
|
||||
|
||||
if not rooms:
|
||||
print("✗ No rooms found in the database! Please seed rooms first.")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"✓ Found {len(rooms)} rooms")
|
||||
|
||||
# Default checklist items for different task types
|
||||
checklists = {
|
||||
'checkout': [
|
||||
{'item': 'Bathroom cleaned', 'completed': False, 'notes': ''},
|
||||
{'item': 'Beds made with fresh linens', 'completed': False, 'notes': ''},
|
||||
{'item': 'Trash emptied', 'completed': False, 'notes': ''},
|
||||
{'item': 'Towels replaced', 'completed': False, 'notes': ''},
|
||||
{'item': 'Amenities restocked', 'completed': False, 'notes': ''},
|
||||
{'item': 'Floor vacuumed and mopped', 'completed': False, 'notes': ''},
|
||||
{'item': 'Surfaces dusted', 'completed': False, 'notes': ''},
|
||||
{'item': 'Windows and mirrors cleaned', 'completed': False, 'notes': ''},
|
||||
],
|
||||
'stayover': [
|
||||
{'item': 'Beds made', 'completed': False, 'notes': ''},
|
||||
{'item': 'Trash emptied', 'completed': False, 'notes': ''},
|
||||
{'item': 'Towels replaced', 'completed': False, 'notes': ''},
|
||||
{'item': 'Bathroom cleaned', 'completed': False, 'notes': ''},
|
||||
],
|
||||
'vacant': [
|
||||
{'item': 'Deep clean bathroom', 'completed': False, 'notes': ''},
|
||||
{'item': 'Change linens', 'completed': False, 'notes': ''},
|
||||
{'item': 'Vacuum and mop', 'completed': False, 'notes': ''},
|
||||
{'item': 'Dust surfaces', 'completed': False, 'notes': ''},
|
||||
{'item': 'Check amenities', 'completed': False, 'notes': ''},
|
||||
],
|
||||
'inspection': [
|
||||
{'item': 'Check all amenities', 'completed': False, 'notes': ''},
|
||||
{'item': 'Test electronics', 'completed': False, 'notes': ''},
|
||||
{'item': 'Check for damages', 'completed': False, 'notes': ''},
|
||||
{'item': 'Verify cleanliness', 'completed': False, 'notes': ''},
|
||||
],
|
||||
}
|
||||
|
||||
# Create tasks for today
|
||||
today = datetime.utcnow().replace(hour=9, minute=0, second=0, microsecond=0)
|
||||
task_types = ['checkout', 'stayover', 'vacant', 'inspection']
|
||||
|
||||
created_count = 0
|
||||
skipped_count = 0
|
||||
|
||||
for i, room in enumerate(rooms):
|
||||
# Cycle through task types
|
||||
task_type = task_types[i % len(task_types)]
|
||||
|
||||
# Check if task already exists for this room today
|
||||
existing_task = db.query(HousekeepingTask).filter(
|
||||
HousekeepingTask.room_id == room.id,
|
||||
HousekeepingTask.assigned_to == housekeeping_user.id,
|
||||
HousekeepingTask.status == HousekeepingStatus.pending,
|
||||
HousekeepingTask.scheduled_time >= today.replace(hour=0, minute=0),
|
||||
HousekeepingTask.scheduled_time < today.replace(hour=23, minute=59, second=59)
|
||||
).first()
|
||||
|
||||
if existing_task:
|
||||
print(f" ⚠️ Task already exists for Room {room.room_number}, skipping...")
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
# Schedule tasks at different times throughout the day
|
||||
scheduled_time = today + timedelta(hours=i)
|
||||
|
||||
task = HousekeepingTask(
|
||||
room_id=room.id,
|
||||
booking_id=None,
|
||||
task_type=HousekeepingType(task_type),
|
||||
status=HousekeepingStatus.pending,
|
||||
scheduled_time=scheduled_time,
|
||||
assigned_to=housekeeping_user.id,
|
||||
created_by=admin_user.id if admin_user else housekeeping_user.id,
|
||||
checklist_items=checklists.get(task_type, []),
|
||||
notes=f'Test task for Room {room.room_number} - {task_type} cleaning',
|
||||
estimated_duration_minutes=45 if task_type == 'checkout' else 30
|
||||
)
|
||||
|
||||
db.add(task)
|
||||
created_count += 1
|
||||
print(f" ✓ Created {task_type} task for Room {room.room_number} (scheduled: {scheduled_time.strftime('%Y-%m-%d %H:%M')})")
|
||||
|
||||
db.commit()
|
||||
|
||||
print(f"\n✓ Tasks assigned successfully!")
|
||||
print(f" - Created: {created_count} task(s)")
|
||||
print(f" - Skipped: {skipped_count} task(s) (already exist)")
|
||||
print(f" - Assigned to: {housekeeping_user.email}")
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"✗ Error assigning housekeeping tasks: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Assigning test housekeeping tasks to housekeeping user...")
|
||||
print("=" * 60)
|
||||
assign_housekeeping_tasks()
|
||||
print("=" * 60)
|
||||
print("Done!")
|
||||
|
||||
@@ -26,7 +26,8 @@ def seed_roles(db: Session):
|
||||
{'name': 'admin', 'description': 'Administrator with full access'},
|
||||
{'name': 'staff', 'description': 'Staff member with limited admin access'},
|
||||
{'name': 'customer', 'description': 'Regular customer'},
|
||||
{'name': 'accountant', 'description': 'Accountant role with access to financial data, payments, and invoices'}
|
||||
{'name': 'accountant', 'description': 'Accountant role with access to financial data, payments, and invoices'},
|
||||
{'name': 'housekeeping', 'description': 'Housekeeping staff role with access to room cleaning tasks and status updates'}
|
||||
]
|
||||
|
||||
for role_data in roles_data:
|
||||
|
||||
Reference in New Issue
Block a user