plugins development

This commit is contained in:
2024-12-10 10:32:46 +09:00
parent 7889117d6e
commit 8dce756a27
10 changed files with 352 additions and 50 deletions

View File

@@ -34,4 +34,22 @@ async def get_reservations(hotel_id, start_date=None, end_date=None):
query = query.filter(check_in__gte=start_date)
if end_date:
query = query.filter(check_out__lte=end_date)
return await sync_to_async(list)(query.prefetch_related('guests'))
return await sync_to_async(list)(query.prefetch_related('guests'))
def save_reservations(data):
"""
Сохранение данных бронирований в базу данных.
:param data: Список бронирований.
"""
for booking in data:
Reservation.objects.update_or_create(
external_id=booking['id'],
defaults={
'check_in': booking['begin_date'],
'check_out': booking['end_date'],
'amount': booking['amount'],
'notes': booking.get('notes', ''),
'guest_name': booking['client']['fio'],
'guest_phone': booking['client']['phone'],
},
)