Push support maybe?
This commit is contained in:
@@ -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,38 +709,65 @@ 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]
|
||||
guest_counts = GuestCountsFactory.create_retrieve_guest_counts(
|
||||
reservation.num_adults, children_ages
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
unique_id_string = reservation.unique_id
|
||||
|
||||
# UniqueID
|
||||
unique_id = OtaResRetrieveRs.ReservationsList.HotelReservation.UniqueId(
|
||||
type_value=UniqueIdType2.VALUE_14, id=unique_id_string
|
||||
)
|
||||
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
|
||||
time_span = OtaResRetrieveRs.ReservationsList.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 = (
|
||||
OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay(
|
||||
time_span=time_span,
|
||||
guest_counts=guest_counts,
|
||||
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
|
||||
else None,
|
||||
end=reservation.end_date.isoformat() if reservation.end_date else None,
|
||||
)
|
||||
room_stay = (
|
||||
OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay(
|
||||
time_span=time_span,
|
||||
guest_counts=guest_counts,
|
||||
)
|
||||
)
|
||||
room_stays = OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays(
|
||||
room_stay=[room_stay],
|
||||
)
|
||||
)
|
||||
room_stays = OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays(
|
||||
room_stay=[room_stay],
|
||||
)
|
||||
|
||||
res_id_source = "website"
|
||||
|
||||
@@ -779,11 +806,16 @@ 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_ids = OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.HotelReservationIds(
|
||||
hotel_reservation_id=[hotel_res_id]
|
||||
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]
|
||||
)
|
||||
|
||||
if reservation.hotel_code is None:
|
||||
raise ValueError("Reservation hotel_code is None")
|
||||
@@ -794,10 +826,16 @@ def create_xml_from_db(list: list[Tuple[Reservation, Customer]]):
|
||||
else:
|
||||
hotel_name = str(reservation.hotel_name)
|
||||
|
||||
basic_property_info = OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.BasicPropertyInfo(
|
||||
hotel_code=hotel_code,
|
||||
hotel_name=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,
|
||||
)
|
||||
# Comments
|
||||
|
||||
offer_comment = None
|
||||
@@ -840,26 +878,45 @@ 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
|
||||
)
|
||||
|
||||
res_global_info = (
|
||||
OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo(
|
||||
hotel_reservation_ids=hotel_res_ids,
|
||||
basic_property_info=basic_property_info,
|
||||
comments=comments_xml,
|
||||
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 = OtaResRetrieveRs.ReservationsList.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,
|
||||
)
|
||||
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,
|
||||
basic_property_info=basic_property_info,
|
||||
comments=comments_xml,
|
||||
)
|
||||
)
|
||||
|
||||
hotel_reservation = OtaResRetrieveRs.ReservationsList.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,
|
||||
)
|
||||
|
||||
reservations_list.append(hotel_reservation)
|
||||
|
||||
@@ -868,21 +925,24 @@ 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
|
||||
)
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
# Usage examples
|
||||
|
||||
Reference in New Issue
Block a user