Push support maybe?

This commit is contained in:
Jonas Linter
2025-10-02 16:41:38 +02:00
parent 325965bb10
commit 9fa4c23719

View File

@@ -671,7 +671,7 @@ class AlpineBitsFactory:
raise ValueError(f"Unsupported object type: {type(obj)}")
def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
def create_xml_from_db(list: list[Tuple[Reservation, Customer]], message_type: OtaMessageType = OtaMessageType.RETRIEVE) -> Union[OtaResRetrieveRs, OtaHotelResNotifRq]:
"""Create RetrievedReservation XML from database entries.
list of pairs (Reservation, Customer)
@@ -709,11 +709,16 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
)
alpine_bits_factory = AlpineBitsFactory()
res_guests = alpine_bits_factory.create_res_guests(
customer_data, OtaMessageType.RETRIEVE
customer_data, message_type
)
# Guest counts
children_ages = [int(a) for a in reservation.children_ages.split(",") if a]
if message_type == OtaMessageType.NOTIF:
guest_counts = GuestCountsFactory.create_notif_guest_counts(
reservation.num_adults, children_ages
)
else:
guest_counts = GuestCountsFactory.create_retrieve_guest_counts(
reservation.num_adults, children_ages
)
@@ -721,11 +726,33 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
unique_id_string = reservation.unique_id
# UniqueID
if message_type == OtaMessageType.NOTIF:
unique_id = OtaHotelResNotifRq.HotelReservations.HotelReservation.UniqueId(
type_value=UniqueIdType2.VALUE_14, id=unique_id_string
)
else:
unique_id = OtaResRetrieveRs.ReservationsList.HotelReservation.UniqueId(
type_value=UniqueIdType2.VALUE_14, id=unique_id_string
)
# TimeSpan
if message_type == OtaMessageType.NOTIF:
time_span = OtaHotelResNotifRq.HotelReservations.HotelReservation.RoomStays.RoomStay.TimeSpan(
start=reservation.start_date.isoformat()
if reservation.start_date
else None,
end=reservation.end_date.isoformat() if reservation.end_date else None,
)
room_stay = (
OtaHotelResNotifRq.HotelReservations.HotelReservation.RoomStays.RoomStay(
time_span=time_span,
guest_counts=guest_counts,
)
)
room_stays = OtaHotelResNotifRq.HotelReservations.HotelReservation.RoomStays(
room_stay=[room_stay],
)
else:
time_span = OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan(
start=reservation.start_date.isoformat()
if reservation.start_date
@@ -779,8 +806,13 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
)
hotel_res_id = alpine_bits_factory.create(
hotel_res_id_data, OtaMessageType.RETRIEVE
hotel_res_id_data, message_type
)
if message_type == OtaMessageType.NOTIF:
hotel_res_ids = OtaHotelResNotifRq.HotelReservations.HotelReservation.ResGlobalInfo.HotelReservationIds(
hotel_reservation_id=[hotel_res_id]
)
else:
hotel_res_ids = OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.HotelReservationIds(
hotel_reservation_id=[hotel_res_id]
)
@@ -794,6 +826,12 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
else:
hotel_name = str(reservation.hotel_name)
if message_type == OtaMessageType.NOTIF:
basic_property_info = OtaHotelResNotifRq.HotelReservations.HotelReservation.ResGlobalInfo.BasicPropertyInfo(
hotel_code=hotel_code,
hotel_name=hotel_name,
)
else:
basic_property_info = OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.BasicPropertyInfo(
hotel_code=hotel_code,
hotel_name=hotel_name,
@@ -840,9 +878,28 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
comments_data = CommentsData(comments=comments)
comments_xml = alpine_bits_factory.create(
comments_data, OtaMessageType.RETRIEVE
comments_data, message_type
)
if message_type == OtaMessageType.NOTIF:
res_global_info = (
OtaHotelResNotifRq.HotelReservations.HotelReservation.ResGlobalInfo(
hotel_reservation_ids=hotel_res_ids,
basic_property_info=basic_property_info,
comments=comments_xml,
)
)
hotel_reservation = OtaHotelResNotifRq.HotelReservations.HotelReservation(
create_date_time=datetime.now(timezone.utc).isoformat(),
res_status=HotelReservationResStatus.REQUESTED,
room_stay_reservation="true",
unique_id=unique_id,
room_stays=room_stays,
res_guests=res_guests,
res_global_info=res_global_info,
)
else:
res_global_info = (
OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo(
hotel_reservation_ids=hotel_res_ids,
@@ -868,20 +925,23 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
f"Error creating XML for reservation {reservation.unique_id} and customer {customer.given_name}: {e}"
)
retrieved_reservations = OtaResRetrieveRs.ReservationsList(
hotel_reservation=reservations_list
)
ota_res_retrieve_rs = OtaResRetrieveRs(
version="7.000", success="", reservations_list=retrieved_reservations
)
if message_type == OtaMessageType.NOTIF:
hotel_reservations = OtaHotelResNotifRq.HotelReservations(hotel_reservation=reservations_list)
ota_res_notif_rq = OtaHotelResNotifRq(version="7.000", hotel_reservations=hotel_reservations)
try:
ota_res_notif_rq.model_validate(ota_res_notif_rq.model_dump())
except Exception as e:
_LOGGER.error(f"Validation error: {e}")
raise
return ota_res_notif_rq
else:
retrieved_reservations = OtaResRetrieveRs.ReservationsList(hotel_reservation=reservations_list)
ota_res_retrieve_rs = OtaResRetrieveRs(version="7.000", success="", reservations_list=retrieved_reservations)
try:
ota_res_retrieve_rs.model_validate(ota_res_retrieve_rs.model_dump())
except Exception as e:
_LOGGER.error(f"Validation error: {e}")
raise
return ota_res_retrieve_rs