From 76176f8a79f8541dafd8eacd4bee00068592987d Mon Sep 17 00:00:00 2001 From: Jonas Linter Date: Mon, 29 Sep 2025 09:42:26 +0200 Subject: [PATCH] Adedd formid as unique id for reservations --- .gitignore | 3 +++ output.xml | 4 ++-- src/alpine_bits_python/db.py | 1 + src/alpine_bits_python/main.py | 12 ++++++++++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 26e0ce5..b0c767a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ test_data/* # ignore secrets secrets.yaml + +# ignore db +alpinebits.db diff --git a/output.xml b/output.xml index 58471d0..ebe3af9 100644 --- a/output.xml +++ b/output.xml @@ -1,8 +1,8 @@ - - + + diff --git a/src/alpine_bits_python/db.py b/src/alpine_bits_python/db.py index 40bf843..4cb2483 100644 --- a/src/alpine_bits_python/db.py +++ b/src/alpine_bits_python/db.py @@ -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) diff --git a/src/alpine_bits_python/main.py b/src/alpine_bits_python/main.py index a6d852d..8833466 100644 --- a/src/alpine_bits_python/main.py +++ b/src/alpine_bits_python/main.py @@ -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(