def __init__(self): #Repos self.cars_info = Cars_repo() self.salesman_info = Salesman_repo() self.customer_info = Customer_repo() self.log_repo = Log_repo() self.get_orders_dict = Orders_repo()
def get_orders(self): customer_orders = [] order_dict = Orders_repo() for orders in order_dict.get_orders().values(): for order in orders: if order.get_cust_email() == self.email: customer_orders.append(order) return customer_orders
def __init__(self): # Repos self.car_repo = Cars_repo() self.order_repo = Orders_repo() self.customer_repo = Customer_repo() # UI's self.error = Print_error() #Utilizations self.__Rent_valid = Rent_validation() self.log_repo = Log_repo() #List self.feature_list = []
def get_orders(self): """Returns list of orders, example list = [[10102018,10122018],[12122018,12142018]], one list represents one order""" order_dict = Orders_repo() order_list = [] valid = False for key, values in order_dict.get_orders().items(): if key == self.plate_number: #check if number plate matches a key in the dict for order in values: pick_up_date = order.get_pick_up_date() drop_off_date = order.get_drop_off_date() date = [pick_up_date, drop_off_date] order_list.append(date) valid = True if valid == True: return order_list else: return []
class Cancel_order_service: def __init__(self): self.orders_repo = Orders_repo() def delete_order(self, key): order_dict = self.orders_repo.get_orders() for plate_num, orders in order_dict.items(): for order in orders: if key == order.get_order_num(): orders.remove(order) self.orders_repo.update_order_file(order_dict) def print_order(self, key): order_dict = self.orders_repo.get_orders() for plate_num, orders in order_dict.items(): for order in orders: if key == order.get_order_num(): return order
class Find_order_service: def __init__(self): #Repos self.orders_repo = Orders_repo() def delete_order(self, key): """Deletes order from the order dictionary and updates the order repository""" order_dict = self.orders_repo.get_orders() for plate_num, orders in order_dict.items(): for order in orders: if key == order.get_order_num(): orders.remove(order) self.orders_repo.update_order_file(order_dict) def get_order(self, key): """Returns the order that matches the order number from the user input""" order_dict = self.orders_repo.get_orders() for plate_num, orders in order_dict.items(): for order in orders: if key == order.get_order_num(): return order
class Salesman_service: def __init__(self): #Repos self.cars_info = Cars_repo() self.salesman_info = Salesman_repo() self.customer_info = Customer_repo() self.log_repo = Log_repo() self.get_orders_dict = Orders_repo() def get_all_cars(self): self.cars_dict = self.cars_info.get_cars() return self.cars_dict.values() def get_available_cars(self): self.available_car_list = [] car_dict = self.cars_info.get_cars() today = datetime.date.today() for value in car_dict.values(): old_orders = value.get_orders() if old_orders != []: for order in old_orders: old_pick_up, old_drop_off = order if (old_pick_up <= today <= old_drop_off): valid = False else: valid = True if valid == True: self.available_car_list.append(value) else: self.available_car_list.append(value) return self.available_car_list def get_unavailable_cars(self): self.unavailable_car_list = [] car_dict = self.cars_info.get_cars() today = datetime.date.today() for value in car_dict.values(): old_orders = value.get_orders() if old_orders != []: for order in old_orders: old_pick_up, old_drop_off = order if (old_pick_up <= today <= old_drop_off): valid = True else: valid = False if valid == True: self.unavailable_car_list.append(value) return self.unavailable_car_list def add_car_repo(self, plate_num, brand, size, location): """Adds car to car repo""" self.new_car = Car(plate_num, brand, size, location) self.cars_info.add_car(plate_num, brand, size, location) def get_customer(self, email): #nær í customer keys úr dict self.customer_dict = self.customer_info.get_customers() #ef keyið passar input frá notanda, returna value úr þeim key for key, value in self.customer_dict.items(): if key == email: self.customer = value return self.customer def order_string(self): """Returns a string of customer orders""" order_string = "" orders = self.customer.get_orders() for order in orders: order_string += "\n" + str(order) + "\n" return order_string def salesman_ID_pw(self, ID, pw): """Takes in pw and id from input and checks if it matches the salesman repository""" valid = False salesman_dict = self.salesman_info.get_salesmen() for key, value in salesman_dict.items(): if key == ID and pw == value.get_password(): self.salesman_id = key self.logged_salesman = value valid = True return valid return valid def change_pw(self, new_pw): """Id is the key in the salesman dictionary, we use the logged in salesman id to find him in the dictionary and update his password by using the change_pw function in the salesman model""" salesman_dict = self.salesman_info.get_salesmen() for key, value in salesman_dict.items(): if key == self.salesman_id: salesman_object = value value.change_pw(new_pw) break self.salesman_info.update_data(salesman_dict) update_repo = self.log_repo update_repo.Update_repo("{} changed his password. ID: {}".format( salesman_object.get_name(), salesman_object.get_ID())) def get_order_info(self, booking_num): order_list = [] order_dict = self.get_orders_dict.get_orders() for values in order_dict.values(): for order in values: if booking_num == order.get_order_num(): order_list.append(order) return order_list def get_log(self): return self.log_repo.Read_repo() def delete_customer(self, customer): """Deletes customer if the email input matches the customer database. Then we update the customer repository.""" cust_dict = self.customer_info.get_customers() cust_dict.pop(customer.get_email()) self.customer_info.add_customers(cust_dict) order_dict = self.get_orders_dict.get_orders() for plate_num, orders in order_dict.items(): for order in orders: if customer.get_email() == order.get_cust_email(): orders.remove(order) self.get_orders_dict.update_order_file(order_dict) def add_to_log(self, ID, brand, plate_num): """Updates log when salesman adds a car to the system""" update_repo = self.log_repo update_repo.Update_repo( "{}, ID: {}, Added {} with plate number {} in {}".format( self.logged_salesman.get_name(), ID, brand, plate_num, self.new_car.get_location_string())) def delete_customer_to_log(self, ID): """Updates log when salesman deletes order""" update_repo = self.log_repo update_repo.Update_repo("{}, ID: {}, deleted customer {} {}".format( self.logged_salesman.get_name(), ID, self.customer.get_first_name(), self.customer.get_last_name()))
class Rent_service: def __init__(self): # Repos self.car_repo = Cars_repo() self.order_repo = Orders_repo() self.customer_repo = Customer_repo() # UI's self.error = Print_error() #Utilizations self.__Rent_valid = Rent_validation() self.log_repo = Log_repo() #List self.feature_list = [] def change_str_to_date(self, num_list): """ Takes in a list with pick up and drop off string and returns a list with pick up and drop off dates.""" pick_up_num, drop_off_num = num_list pick_up_date = datetime.date(int(pick_up_num[4:8]), int(pick_up_num[:2]), int(pick_up_num[2:4])) drop_off_date = datetime.date(int(drop_off_num[4:8]), int(drop_off_num[:2]), int(drop_off_num[2:4])) return [pick_up_date, drop_off_date] def find_available_cars(self, date, size, location): """Get car_dict from repo and get inputs from Rent controller. Compare to get available car.""" self.available_car_list = [] car_dict = self.car_repo.get_cars() for value in car_dict.values(): if location == value.get_location() and size == value.get_car_size( ): new_pick_up_date, new_drop_off_date = date old_orders = value.get_orders() if old_orders != []: for order in old_orders: old_pick_up, old_drop_off = order if (old_drop_off < new_pick_up_date and old_drop_off < new_drop_off_date) or \ (old_pick_up > new_pick_up_date and old_pick_up > new_drop_off_date): valid = True else: valid = False break if valid == True: self.available_car_list.append(value) else: self.available_car_list.append(value) return self.available_car_list def get_car_size_string(self, choice): """Converts choice of size (1,2,3) to a string which represents the size name (Small, Medium, SUVs)""" if choice == "1": string = "Small cars:" elif choice == "2": string = "Medium cars:" elif choice == "3": string = "SUVs:" return string def make_carlist_string(self, available_car_list): """Constructs a string made from the car_list to print out for the user""" carlist_string = "" for index, car in enumerate(available_car_list): carlist_string += ("\n\t\t\t Car {:>3}: {:>12}{:>10} kr.".format( index + 1, car.get_brand(), car.get_pri_ins()[0])) return carlist_string def get_desired_car(self, car_choice): """Uses self.user_input to index car in the car_list, makes the car object, self.desired_car""" num_choice = int(car_choice) self.desired_car = self.available_car_list[num_choice - 1] return self.desired_car def desired_car_info(self): "Takes the desired car object and return all of its attributes in a string" string = "" string += "\t\t\t\t ~~{}~~\n".format(self.desired_car.get_brand()) string += "\n" string += "\t\t\t\tLocation: {}\n".format( self.desired_car.get_location_string()) price, insurance = self.desired_car.get_pri_ins() string += "\t\t\t\tBase price: {} kr.\n\t\t\t\tInsurance: {} kr.".format( price, insurance) return string def get_feature_string(self, choice): """Converts user_input (1,2,3) to string (GPS, Baby chair, Extra Insurance)""" if choice == "1": return "GPS" elif choice == "2": return "Baby chair" elif choice == "3": return "Extra Insurance" def get_index(self): """Get index of the additional feature the user wants to remove""" for index, feature in enumerate(self.feature_list): if feature == self.user_input: return index def add_features(self, choice): """Adds features to list, returns list""" self.user_input = choice # Get string from the user_input which we then use when printing added! or removed! statements. feature_string = self.get_feature_string(choice) # Get index of the user_input to find it in the list, returns the index and then we # use the index to remove the feature from the list index = self.get_index() if choice not in self.feature_list: # If valid feature and not already in feature_list print("\t\t\t\t{} added!".format(feature_string)) self.feature_list.append(choice) input("\t\t\t\tPress enter to continue") elif choice in self.feature_list: # If already in feature_list it is removed from it print("\t\t\t\t{} removed!".format(feature_string)) self.feature_list.pop(index) input("\t\t\t\tPress enter to continue") return self.feature_list def reset_features(self): """ Resets the list of features """ self.feature_list = [] self.feature_string = "" return self.feature_list, self.feature_string def get_price(self, feature_list, car_obj): """Returns final price for the customer, takes the list of additional features and calculates the price.""" price, insurance = car_obj.get_pri_ins() additional_price = int(insurance) for feature in feature_list: if feature == "1": additional_price += 5000 elif feature == "2": additional_price += 1000 elif feature == "3": additional_price += 6500 return additional_price, int(price) def make_date_str(self, date): """Takes the self.__date_list and turns it into a string""" pick_up, drop_off = date date_info = "\t\t\t\tPickup date: {}\n\t\t\t\tDrop off date: {}".format( pick_up, drop_off) return date_info def make_feature_string(self, choice): feature_string = "" for choice in self.feature_list: feature_string += "\t\t\t\t{}\n".format( self.get_feature_string(choice)) if feature_string == "": return "None\n" return feature_string def make_booking_num(self): """Makes booking number from order dictionary""" book_list = [] for key, values in self.order_repo.get_orders().items(): for order in values: book_list.append(int(order.get_order_num())) if book_list != []: book_num = max(book_list) + 1 else: book_num = 1 return book_num def add_order_to_dict(self, booking_num, email, plate_num, date_list): """Adds order to order dictionary with all the information from the user input. Also updates order repository with the new dictionary""" new_pick_up, drop_off = date_list new_order = Order(booking_num, new_pick_up, drop_off, plate_num, email) order_dict = self.order_repo.get_orders() if order_dict != {}: for key, values in order_dict.items(): if key == plate_num: values.append(new_order) break elif plate_num not in order_dict: order_dict[plate_num] = [new_order] break else: order_dict[plate_num] = [new_order] self.order_repo.update_order_file(order_dict) def update_customer_repo(self, new_customer): email = new_customer.get_email() customer_dict = self.customer_repo.get_customers() customer_dict[email] = new_customer self.customer_repo.add_customers(customer_dict) def update_log(self, first_name, last_name, car_obj, date_list): """Updates log repository when a customer books a car""" update_repo = self.log_repo update_repo.Update_repo( "{} {} booked {}, {}. Pick up date: {}, Drop off date {}\n".format( first_name, last_name, car_obj.get_brand(), car_obj.get_plate_number(), date_list[0], date_list[1]))
def __init__(self): self.orders_repo = Orders_repo()
def __init__(self): #Repos self.orders_repo = Orders_repo()