Adedd formid as unique id for reservations

This commit is contained in:
Jonas Linter
2025-09-29 09:42:26 +02:00
parent 4416397a69
commit 76176f8a79
4 changed files with 16 additions and 4 deletions

3
.gitignore vendored
View File

@@ -20,3 +20,6 @@ test_data/*
# ignore secrets # ignore secrets
secrets.yaml secrets.yaml
# ignore db
alpinebits.db

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="7.000"> <OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="7.000">
<ReservationsList> <ReservationsList>
<HotelReservation CreateDateTime="2025-09-29T07:21:12.768928+00:00" ResStatus="Requested" RoomStayReservation="true"> <HotelReservation CreateDateTime="2025-09-29T07:33:12.122570+00:00" ResStatus="Requested" RoomStayReservation="true">
<UniqueID Type="14" ID="6b34fe24ac2ff811"/> <UniqueID Type="14" ID="e084006b-ae83-4e4d-b2f5-074118cdb3b1"/>
<RoomStays> <RoomStays>
<RoomStay> <RoomStay>
<GuestCounts> <GuestCounts>

View File

@@ -26,6 +26,7 @@ class Reservation(Base):
__tablename__ = 'reservations' __tablename__ = 'reservations'
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
customer_id = Column(Integer, ForeignKey('customers.id')) customer_id = Column(Integer, ForeignKey('customers.id'))
form_id = Column(String, unique=True)
start_date = Column(Date) start_date = Column(Date)
end_date = Column(Date) end_date = Column(Date)
num_adults = Column(Integer) num_adults = Column(Integer)

View File

@@ -46,6 +46,10 @@ def main():
os.makedirs(db_dir, exist_ok=True) os.makedirs(db_dir, exist_ok=True)
# The DB file will be created by SQLAlchemy if it doesn't exist, but ensure directory exists # The DB file will be created by SQLAlchemy if it doesn't exist, but ensure directory exists
# for now we delete the existing DB for clean testing
if os.path.exists(db_path):
os.remove(db_path)
print(f"Deleted existing SQLite DB at {db_path} for clean testing.")
# Init DB # Init DB
init_db(config) init_db(config)
@@ -144,6 +148,7 @@ def main():
db_reservation = DBReservation( db_reservation = DBReservation(
customer_id=db_customer.id, customer_id=db_customer.id,
form_id=data.get("formId"),
start_date=date.fromisoformat(start_date) if start_date else None, start_date=date.fromisoformat(start_date) if start_date else None,
end_date=date.fromisoformat(end_date) if end_date else None, end_date=date.fromisoformat(end_date) if end_date else None,
num_adults=num_adults, num_adults=num_adults,
@@ -159,9 +164,12 @@ def main():
# Success - use None instead of object() for cleaner XML output # Success - use None instead of object() for cleaner XML output
success = None success = None
# UniqueID # UniqueID, we are using the formid as a stable unique id
form_id = data.get("formId")
# hardcoding the type to 14 is allowed because 15 is only for cancellations and we don't handle those
unique_id = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.UniqueId( unique_id = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.UniqueId(
type_value=ab.UniqueIdType2.VALUE_14, id="6b34fe24ac2ff811" type_value=ab.UniqueIdType2.VALUE_14, id=form_id
) )
time_span = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan( time_span = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan(