Shelter PMS fully functional
This commit is contained in:
@@ -4,7 +4,11 @@ from bot.operations.hotels import manage_hotels, hotel_actions, delete_hotel, ch
|
||||
from bot.operations.statistics import statistics, stats_select_period, generate_statistics
|
||||
from bot.operations.settings import settings_menu, toggle_telegram, toggle_email, set_notification_time, show_current_settings
|
||||
from bot.operations.users import show_users
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from pms_integration.api_client import APIClient
|
||||
|
||||
from users.models import User, NotificationSettings
|
||||
from hotels.models import Hotel
|
||||
|
||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""Обработчик команды /start."""
|
||||
@@ -93,3 +97,27 @@ async def navigate_back(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await hotel_actions(update, context)
|
||||
else:
|
||||
await update.callback_query.edit_message_text("Команда не распознана.")
|
||||
|
||||
|
||||
async def sync_hotel_data(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""Синхронизация данных отеля через API."""
|
||||
user_id = update.effective_user.id
|
||||
|
||||
try:
|
||||
user = User.objects.get(chat_id=user_id)
|
||||
hotels = Hotel.objects.filter(hotel_users__user=user)
|
||||
except ObjectDoesNotExist:
|
||||
await update.message.reply_text("Вы не зарегистрированы.")
|
||||
return
|
||||
|
||||
if not hotels:
|
||||
await update.message.reply_text("У вас нет доступных отелей для синхронизации.")
|
||||
return
|
||||
|
||||
for hotel in hotels:
|
||||
try:
|
||||
client = APIClient(hotel.pms)
|
||||
client.run(hotel)
|
||||
await update.message.reply_text(f"Данные отеля {hotel.name} успешно синхронизированы.")
|
||||
except Exception as e:
|
||||
await update.message.reply_text(f"Ошибка синхронизации для {hotel.name}: {str(e)}")
|
||||
Reference in New Issue
Block a user