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

View File

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

View File

@@ -46,6 +46,10 @@ def main():
os.makedirs(db_dir, exist_ok=True)
# 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(config)
@@ -144,6 +148,7 @@ def main():
db_reservation = DBReservation(
customer_id=db_customer.id,
form_id=data.get("formId"),
start_date=date.fromisoformat(start_date) if start_date else None,
end_date=date.fromisoformat(end_date) if end_date else None,
num_adults=num_adults,
@@ -159,9 +164,12 @@ def main():
# Success - use None instead of object() for cleaner XML output
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(
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(