def booking_add(self): print(Fore.RED, " Add Booking ".center(30, "*"), Fore.RESET) guest = Guest_service() guest_id = guest.search_guest() Apartments = Apartment_service() apartments = Apartments.search_apartment() rowIdx = get_int("Please select apt number: ", 0, len(apartments)) apartment = apartments[rowIdx] apartment_price = apartment.price booking = Booking() booking.guest_id = guest_id booking.booked_date = datetime.datetime.now() booking.chek_in_date = get_date("Input Data") booking.chek_out_date = get_date("Input Data") if (apartments == None or len(apartments) == 0): print("Error") return apartment.bookings.append(booking) apartment.save() columns = ("Chek_in_date", "Chek_out_date", "Booked_date") pretty_print([booking], columns) print("{}Booking duration is {} day(s).{}".format(Fore.YELLOW, booking.duration, Fore.RESET)) print("{}TOTAL Price {} USD.{}".format(Fore.YELLOW, apartment_price * booking.duration, Fore.RESET)) print(Fore.RED, " Apartment Saved".center(30, "*"), Fore.RESET)
def SaveBooking(self): guest = Guest_service() guest_id = guest.search_guest(guest_name=self.user_line_edit.text()) Apartments = Apartment_service() apartments = Apartments.search_apartment( name=self.apt_line_edit.text()) apartment = apartments[0] apartment_price = apartment.price if (apartments == None or len(apartments) == 0): print("Error") return data = { "name": self.apt_line_edit.text(), "guest_name": self.user_line_edit.text(), "guest_id": guest_id, "booked_date": datetime.datetime.now(), "chek_in_date": self.parceDate(data=self.check_in.text()), "chek_in_date": self.parceDate(data=self.check_out.text()), "price": apartment_price } #self.model.updateRow(self.rowIdx, data) booking = Booking_service() booking.booking_add(data)
def RenderGuestsTable(self): table = QTableView(self) table.setMaximumWidth(500) table.setEditTriggers(QAbstractItemView.NoEditTriggers) table.setSelectionBehavior(QAbstractItemView.SelectRows) table.setSelectionMode(QAbstractItemView.SingleSelection) table.clicked.connect(self.RowSelected) guests = Guest_service() self.guests_data = guests.guest_list() self.model = GuestsTableModel(self.guests_data, guests) table.setModel(self.model) return table
def booking_seach_by_name(self): """ View booking by Guest name Input (str) - guest name Output - print table Bookings """ print(Fore.RED, " Seach Booking by Name".center(30, "*"), Fore.RESET) # Повертаємо ID гостя guest = Guest_service() guest_id = guest.search_guest() # це друкую для виключно перевірки print(Fore.YELLOW, "You ID = ", guest_id, Fore.RESET) columns_apt = ("Name", "price") columns_booking = ("guest_id", "chek_in_date", "chek_out_date", "booked_date") message = "You haven't bookings yet!" # Перевіряємо чи є бронювання for apartment in Apartment.objects(bookings__guest_id=guest_id): guest_bookings = [] # Перевіряємо чи це бронювання нашого гостя for booking in apartment.bookings: if booking.guest_id == guest_id: guest_bookings.append(booking) # якщо є бронювання друкуємо назву апартаментів та бронювання if len(guest_bookings) > 0: print(Fore.YELLOW, "You boking(s) in " + apartment.name, Fore.RESET) pretty_print(guest_bookings, columns_booking) message = '' # якщо зовсім немає бронювань дкукуємо повідомлення if message != '': print(Fore.YELLOW, message, Fore.RESET)
def get_guests(self): guest_service = Guest_service() self.user_list = guest_service.get_guests()