filters, reports
This commit is contained in:
@@ -45,6 +45,7 @@ async def stats_select_period(update: Update, context: ContextTypes.DEFAULT_TYPE
|
||||
context.user_data["selected_hotel"] = hotel_id
|
||||
|
||||
keyboard = [
|
||||
[InlineKeyboardButton("День", callback_data="stats_period_day")],
|
||||
[InlineKeyboardButton("Неделя", callback_data="stats_period_week")],
|
||||
[InlineKeyboardButton("Месяц", callback_data="stats_period_month")],
|
||||
[InlineKeyboardButton("Все время", callback_data="stats_period_all")],
|
||||
@@ -67,19 +68,32 @@ async def generate_statistics(update: Update, context: ContextTypes.DEFAULT_TYPE
|
||||
period = query.data.split("_")[2]
|
||||
|
||||
now = datetime.now()
|
||||
if period == "week":
|
||||
start_date = now - timedelta(days=7)
|
||||
end_date = now
|
||||
if period == "day":
|
||||
start_date = (now - timedelta(days=1)).date() # Вчерашняя дата
|
||||
end_date = now.date() # Сегодняшняя дата
|
||||
elif period == "week":
|
||||
start_date = (now - timedelta(days=7)).date()
|
||||
end_date = now.date()
|
||||
elif period == "month":
|
||||
start_date = now - timedelta(days=30)
|
||||
end_date = now
|
||||
start_date = (now - timedelta(days=30)).date()
|
||||
end_date = now.date()
|
||||
else:
|
||||
start_date = None
|
||||
end_date = None
|
||||
|
||||
reservations = await sync_to_async(list)(
|
||||
Reservation.objects.filter(hotel_id=hotel_id).prefetch_related('guests')
|
||||
)
|
||||
# Фильтрация по "дата заезда"
|
||||
if start_date and end_date:
|
||||
reservations = await sync_to_async(list)(
|
||||
Reservation.objects.filter(
|
||||
hotel_id=hotel_id,
|
||||
check_in__date__gte=start_date,
|
||||
check_in__date__lte=end_date
|
||||
).prefetch_related('guests')
|
||||
)
|
||||
else:
|
||||
reservations = await sync_to_async(list)(
|
||||
Reservation.objects.filter(hotel_id=hotel_id).prefetch_related('guests')
|
||||
)
|
||||
|
||||
if not reservations:
|
||||
await query.edit_message_text("Нет данных для статистики за выбранный период.")
|
||||
@@ -92,6 +106,7 @@ async def generate_statistics(update: Update, context: ContextTypes.DEFAULT_TYPE
|
||||
await query.message.reply_document(document=file, filename=f"{hotel.name}_report.pdf")
|
||||
|
||||
|
||||
|
||||
async def stats_back(update: Update, context):
|
||||
"""Возврат к выбору отеля."""
|
||||
query = update.callback_query
|
||||
|
||||
Reference in New Issue
Block a user