示例#1
0
def add_reservation(hotel_id, room_type, arrival_date, departure_date, status):
    """
    Add a new reservation to the system
    """
    session = DBSession().get_db_session()
    # Check for invalid room type (doesn't exist in inventory for desired hotel)
    room_type_inventory = session.query(HotelInventory).filter(HotelInventory.hotel_id == hotel_id) \
                                                       .filter(HotelInventory.room_type == room_type)
    if len(room_type_inventory.all()) != 1:
        return OPERATION_ERROR_RETURN_CODE
    # Check for invalid reservation dates
    arrival_date = create_datetime_object(arrival_date)
    departure_date = create_datetime_object(departure_date)
    if departure_date <= arrival_date or arrival_date < datetime.date.today():
        return OPERATION_ERROR_RETURN_CODE
    # Check availability in inventory before adding reservation
    max_occupancy = room_type_inventory.first().room_inventory
    for date in generate_days_list(arrival_date, departure_date):
        if not get_occupancy(hotel_id, date, room_type) < max_occupancy:
            return OPERATION_ERROR_RETURN_CODE
    reservation = Reservations(hotel_id=hotel_id,
                               room_type=room_type,
                               arrival_date=arrival_date,
                               departure_date=departure_date,
                               status=status)
    session.add(reservation)
    session.commit()
    return reservation.id
示例#2
0
def cancel_reservation(reservation_id):
    """
    Cancel an existing reservation. Note: this will only change the reservation's status to "Cancelled".
    """
    session = DBSession().get_db_session()
    reservation = session.query(Reservations).get(reservation_id)
    reservation.status = CANCELLED_STATUS
    session.commit()
示例#3
0
def add_hotel(hotel_name):
    """
    Add a new hotel to the system
    """
    session = DBSession().get_db_session()
    hotel = Hotels(hotel_name=hotel_name)
    session.add(hotel)
    session.commit()
    return hotel.id
示例#4
0
def activate_reservation(reservation_id):
    """
    Activate an existing reservation. Note: this will only change the reservation's status to "Active".
    """
    session = DBSession().get_db_session()
    # If this functionality ever becomes an endpoint to 3rd parties, make sure to check
    # availability in inventory before activating reservation
    reservation = session.query(Reservations).get(reservation_id)
    reservation.status = ACTIVE_STATUS
    session.commit()
示例#5
0
def add_inventory(hotel_id, room_type, room_inventory):
    """
    Add an inventory record to the system
    """
    session = DBSession().get_db_session()
    # If this functionality ever becomes a real endpoint to 3rd parties, make sure to check
    # inventory for this room type, make sure it is new type
    inventory = HotelInventory(hotel_id=hotel_id,
                               room_type=room_type,
                               room_inventory=room_inventory)
    session.add(inventory)
    session.commit()