import_history.log deletion
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
# Generated by Django 5.1.4 on 2024-12-14 00:19
|
||||
# hotels/migrations/0006_remove_hotel_import_status_remove_hotel_imported_at_and_more.py
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
def remove_unused_fields(apps, schema_editor):
|
||||
Hotel = apps.get_model('hotels', 'Hotel')
|
||||
Hotel._meta.get_field('import_status').remote_field.model._meta.db_table
|
||||
Hotel._meta.get_field('imported_at').remote_field.model._meta.db_table
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -10,10 +14,6 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='hotel',
|
||||
name='api',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='hotel',
|
||||
name='import_status',
|
||||
@@ -26,4 +26,8 @@ class Migration(migrations.Migration):
|
||||
model_name='hotel',
|
||||
name='imported_from',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='hotel',
|
||||
name='api',
|
||||
),
|
||||
]
|
||||
|
||||
23347
import_hotels.log
23347
import_hotels.log
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
import requests
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from asgiref.sync import sync_to_async
|
||||
from pms_integration.models import PMSConfiguration
|
||||
@@ -14,7 +13,6 @@ class EcviPMSPlugin(BasePMSPlugin):
|
||||
"""
|
||||
|
||||
def __init__(self, pms_config):
|
||||
# Инициализация родительского конструктора
|
||||
super().__init__(pms_config)
|
||||
|
||||
# Инициализация логгера
|
||||
@@ -40,7 +38,7 @@ class EcviPMSPlugin(BasePMSPlugin):
|
||||
"field_mapping": {
|
||||
"check_in": "checkin",
|
||||
"check_out": "checkout",
|
||||
"room_number": "room_name", # Заменили на room_number
|
||||
"room_number": "room_name",
|
||||
"room_type_name": "room_type",
|
||||
"status": "occupancy",
|
||||
},
|
||||
@@ -73,15 +71,20 @@ class EcviPMSPlugin(BasePMSPlugin):
|
||||
return []
|
||||
|
||||
# Фильтрация данных
|
||||
filtered_data = [
|
||||
{
|
||||
'checkin': datetime.strptime(item.get('checkin'), '%Y-%m-%d %H:%M:%S'),
|
||||
'checkout': datetime.strptime(item.get('checkout'), '%Y-%m-%d %H:%M:%S'),
|
||||
'room_name': item.get('room_name'),
|
||||
'room_type': item.get('room_type'),
|
||||
'status': item.get('occupancy')
|
||||
} for item in data if item.get('occupancy') in ['проживание', 'под выезд', 'под заезд']
|
||||
]
|
||||
filtered_data = []
|
||||
for item in data:
|
||||
if item.get('occupancy') in ['проживание', 'под выезд', 'под заезд']:
|
||||
filtered_item = {
|
||||
'checkin': datetime.strptime(item.get('checkin'), '%Y-%m-%d %H:%M:%S'),
|
||||
'checkout': datetime.strptime(item.get('checkout'), '%Y-%m-%d %H:%M:%S'),
|
||||
'room_number': item.get('room_name'),
|
||||
'room_type': item.get('room_type'),
|
||||
'status': item.get('occupancy')
|
||||
}
|
||||
filtered_data.append(filtered_item)
|
||||
|
||||
# Логируем результат фильтрации
|
||||
self.logger.debug(f"Отфильтрованные данные: {filtered_data}")
|
||||
|
||||
# Сохранение данных в базу данных
|
||||
for item in filtered_data:
|
||||
@@ -95,16 +98,24 @@ class EcviPMSPlugin(BasePMSPlugin):
|
||||
Сохраняет данные в БД (например, информацию о номере).
|
||||
"""
|
||||
try:
|
||||
# Проверяем, что item — это словарь
|
||||
if not isinstance(item, dict):
|
||||
self.logger.error(f"Ожидался словарь, но получен: {type(item)}. Данные: {item}")
|
||||
return
|
||||
|
||||
# Получаем отель по настройкам PMS
|
||||
hotel = await sync_to_async(Hotel.objects.get)(pms=self.pms_config)
|
||||
self.logger.debug(f"Отель найден: {hotel.name}")
|
||||
|
||||
# Сохраняем данные бронирования
|
||||
room_number = item.get("room_name")
|
||||
room_number = item.get("room_number")
|
||||
check_in = item.get("checkin")
|
||||
check_out = item.get("checkout")
|
||||
room_type = item.get("room_type")
|
||||
|
||||
# Логируем полученные данные
|
||||
self.logger.debug(f"Полученные данные для сохранения: room_number={room_number}, check_in={check_in}, check_out={check_out}, room_type={room_type}")
|
||||
|
||||
# Проверяем, существует ли запись с таким номером и датой заезда
|
||||
existing_reservation = await sync_to_async(
|
||||
Reservation.objects.filter(room_number=room_number, check_in=check_in).first
|
||||
@@ -124,14 +135,15 @@ class EcviPMSPlugin(BasePMSPlugin):
|
||||
self.logger.debug(f"Обновлена существующая резервация.")
|
||||
else:
|
||||
self.logger.debug(f"Резервация не найдена, создаем новую...")
|
||||
await sync_to_async(Reservation.objects.create)(
|
||||
reservation = await sync_to_async(Reservation.objects.create)(
|
||||
room_number=room_number,
|
||||
check_in=check_in,
|
||||
check_out=check_out,
|
||||
hotel=hotel,
|
||||
room_type=room_type,
|
||||
)
|
||||
self.logger.debug(f"Создана новая резервация.")
|
||||
self.logger.debug(f"Создана новая резервация. ID: {reservation.reservation_id}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Ошибка сохранения данных: {e}")
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ SECRET_KEY = 'django-insecure-l_8uu8#p*^zf)9zry80)6u+!+2g1a4tg!wx7@^!uw(+^axyh&h
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['0.0.0.0', '192.168.219.140', '127.0.0.1', '192.168.219.114', 'c710-182-226-158-253.ngrok-free.app']
|
||||
ALLOWED_HOSTS = ['0.0.0.0', '192.168.219.140', '127.0.0.1', '192.168.219.114', '0533-182-226-158-253.ngrok-free.app']
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'https://c710-182-226-158-253.ngrok-free.app',
|
||||
'https://0533-182-226-158-253.ngrok-free.app',
|
||||
'https://*.ngrok.io', # Это подойдет для любых URL, связанных с ngrok
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user