def delete_object(list): item = input("What would you like to delete? \n").title() if item in list: list.remove(item) os.system("clear") print(f" {item} has been removed from the list") module_print.print_object(list) elif item not in list: print(f"Product selected {item} does not exist")
def start_program(): choice_main_menu = module_menus.main_menu() while choice_main_menu != "0": if choice_main_menu == "1": os.system("clear") choice_product_menu = module_menus.product_menu() # used a while loop to go thru everything in product menu while choice_product_menu != "0": if choice_product_menu == "1": os.system("clear") # module_print.print_object(ready_meal) module_print.print_data("product.csv") # loopet backed at line 61 after we done everything in the if block choice_product_menu = module_menus.product_menu() elif choice_product_menu == "2": os.system("clear") new_product = input("What meal would you like to add? \n").title() product_price = input("What is the price of the meal? \n").title() if not new_product in product: # use statment to ckeck if the item is already in the list product.append( {'Name': new_product, 'Price': product_price} ) module_save.save_product(product) # save_orders(order) # module_add.add_new_object(new_product, ready_meal) # module_save.save_lists("ready_meal.txt", ready_meal) else: print(f"{new_product} is already in the list") new_product2 = input("Do you want to add another one? Yes or No \n").title() os.system("clear") if new_product2 != "No": new_product3 = input("What meal would you like to add? \n").title() new_product_price = input("What is the price of the meal? \n").title() print("Your new meal is: " + new_product3 + " for " + new_product_price) product.append( {'Name': new_product, 'Price': product_price} ) module_save.save_product(product) # looped back to line 61 after checking everything in elif block choice_product_menu = module_menus.product_menu() elif choice_product_menu == "3": os.system("clear") module_print.print_object(ready_meal) product_to_update = input("What product would you like to update? \n").title() if product_to_update not in ready_meal: print(f"Product selected {product_to_update} does not exist") else: updated_product = input("What would you like to update this to? \n").title() update_object(product_to_update, updated_product, ready_meal) module_save.save_lists("ready_meal.txt", ready_meal) # index_value = list.index(product_to_update) choice_product_menu = module_menus.product_menu() elif choice_product_menu == "4": os.system("clear") # module_print.print_object(ready_meal) module_print.print_data("product.csv") module_add.delete_meal() # module_add.delete_object(ready_meal) module_save.save_lists("ready_meal.txt", ready_meal) choice_product_menu = module_menus.product_menu() else: os.system("clear") print("Option selected is invalid") choice_product_menu = module_menus.product_menu() os.system("clear") choice_main_menu = module_menus.main_menu() elif choice_main_menu == "2": os.system("clear") choice_courier_menu = module_menus.courier_menu() while choice_courier_menu != "0": if choice_courier_menu == "1": os.system("clear") module_print.print_data("courier.csv") # loopet backed at line 61 after we done everything in the if block choice_courier_menu = module_menus.courier_menu() elif choice_courier_menu == "2": os.system("clear") new_courier = input("What name would you like to add? \n").title() courier_phone = input("What is the phone number? \n").title() courier.append( {'Name': new_courier, 'Phone': courier_phone} ) module_save.save_courier(courier) choice_courier_menu = module_menus.courier_menu() elif choice_courier_menu == "3": os.system("clear") module_print.print_object(courier) courier_to_update = input("What courier would you like to update? \n").title() updated_courier = input("What would you like to update this to? \n").title() update_object(courier_to_update, updated_courier, courier) module_save.save_lists("courier.txt", courier) choice_courier_menu = module_menus.courier_menu() elif choice_courier_menu == "4": os.system("clear") module_add.delete_object(courier) module_save.save_lists("courier.txt", courier) choice_courier_menu = module_menus.courier_menu() else: os.system("clear") print("Option selected is invalid") choice_product_menu = module_menus.product_menu() os.system("clear") choice_main_menu = module_menus.main_menu() elif choice_main_menu == "3": os.system("clear") choice_order_menu = module_menus.order_menu() while choice_order_menu != "0": if choice_order_menu == "1": module_print.print_data("order.csv") # order_menu() choice_order_menu = module_menus.order_menu() elif choice_order_menu == "2": os.system("clear") # add a key and a value in dictionary use cap input name = input("Please enter the name of new order \n").title() address = input("Please type the address for delivery \n").title() phone = input("Please enter phone number \n").title() delv_method = input("Please add the delivery method \n").title() status = input("Please enter the status of the order \n").title() # product_choice_input = "" # List for all the items user selected product_selection = [] while product_choice_input != "0": # prints all the items module_print.print_data("product.csv") # takes the input product_choice_input = input("Select product from list below or type 0 to return \n").title() if product_choice_input != 0: # add the user input to the list of items as long as it's not zero product_selection.append(product_choice_input) # for order in orders: # if order['Name'] == "Order 1": # order['Statis'] = "Shipping" # Needs an array for the product order.append( {'Name': name, 'Address': address, 'Phone': phone, 'Courier': delv_method, 'Status': status, 'Items': ','.join(product_selection)} ) save_orders(order) module_print.print_data("order.csv") # Have to call save_lists to save it to the file # add_new_object(name, courier) # module_save.save_lists('courier.txt', courier) # save_orders(order) choice_order_menu = module_menus.order_menu() elif choice_order_menu == "3": os.system("clear") # print key and values from dictionary on different lines module_print.read_orders() # select key to delete from dictionary, use title for capitalize input select_order = input("Please select a order to delete \n") try: # del order[index] for index, item in enumerate(order): if select_order in item.values(): del order[index] save_orders(order) delete_lists("courier.txt", select_order) print(f" {select_order} has been removed from the list") module_print.read_orders() choice_order_menu = module_menus.order_menu() except KeyError: print(f"order selected {select_order} does not exist") choice_order_menu = module_menus.order_menu() elif choice_order_menu == "4": os.system("clear") else: os.system("clear") print("Option selected is invalid") choice_order_menu = module_menus.order_menu() os.system("clear") choice_main_menu = module_menus.main_menu()
def add_new_object(item, list): list.append(item) module_print.print_object(list)
def start_program(): choice_main_menu = module_menus.main_menu() while choice_main_menu != "0": if choice_main_menu == "1": os.system("clear") choice_product_menu = module_menus.product_menu() # used a while loop to go thru everything in product menu while choice_product_menu != "0": if choice_product_menu == "1": os.system("clear") module_print.print_object(ready_meal) # loopet backed at line 61 after we done everything in the if block choice_product_menu = module_menus.product_menu() elif choice_product_menu == "2": os.system("clear") new_product = input( "What meal would you like to add? \n").title() if not new_product in ready_meal: # use statment to ckeck if the item is already in the list module_add.add_new_object(new_product, ready_meal) module_save.save_lists("ready_meal.txt", ready_meal) else: print(f"{new_product} is already in the list") new_product2 = input( "Do you want to add another one? Yes or No \n").title( ) os.system("clear") if new_product2 != "No": new_product3 = input( "What meal would you like to add? \n").title() print("Your new meal is: " + new_product3) module_add.add_new_object(new_product3, ready_meal) module_save.save_lists("ready_meal.txt", ready_meal) # looped back to line 61 after checking everything in elif block choice_product_menu = module_menus.product_menu() elif choice_product_menu == "3": os.system("clear") module_print.print_object(ready_meal) product_to_update = input( "What product would you like to update? \n").title() if product_to_update not in ready_meal: print( f"Product selected {product_to_update} does not exist" ) else: updated_product = input( "What would you like to update this to? \n").title( ) update_object(product_to_update, updated_product, ready_meal) module_save.save_lists("ready_meal.txt", ready_meal) # index_value = list.index(product_to_update) choice_product_menu = module_menus.product_menu() elif choice_product_menu == "4": os.system("clear") module_print.print_object(ready_meal) module_add.delete_object(ready_meal) module_save.save_lists("ready_meal.txt", ready_meal) choice_product_menu = module_menus.product_menu() else: os.system("clear") print("Option selected is invalid") choice_product_menu = module_menus.product_menu() os.system("clear") choice_main_menu = module_menus.main_menu() elif choice_main_menu == "2": os.system("clear") choice_courier_menu = module_menus.courier_menu() while choice_courier_menu != "0": if choice_courier_menu == "1": os.system("clear") module_print.print_object(courier) # loopet backed at line 61 after we done everything in the if block choice_courier_menu = module_menus.courier_menu() elif choice_courier_menu == "2": os.system("clear") new_courier = input( "What name would you like to add? \n").title() module_add.add_new_object(new_courier, courier) module_save.save_lists("courier.txt", courier) choice_courier_menu = module_menus.courier_menu() elif choice_courier_menu == "3": os.system("clear") module_print.print_object(courier) courier_to_update = input( "What courier would you like to update? \n").title() updated_courier = input( "What would you like to update this to? \n").title() update_object(courier_to_update, updated_courier, courier) save_lists("courier.txt", courier) choice_courier_menu = module_menus.courier_menu() elif choice_courier_menu == "4": os.system("clear") module_add.delete_object(courier) module_save.save_lists("courier.txt", courier) choice_courier_menu = module_menus.courier_menu() else: os.system("clear") print("Option selected is invalid") choice_product_menu = module_menus.product_menu() os.system("clear") choice_main_menu = module_menus.main_menu() elif choice_main_menu == "3": os.system("clear") choice_order_menu = module_menus.order_menu() while choice_order_menu != "0": if choice_order_menu == "1": module_print.read_orders() # order_menu() choice_order_menu = module_menus.order_menu() elif choice_order_menu == "2": os.system("clear") # add a key and a value in dictionary use cap input name = input( "Please enter the name of new order \n").title() address = input( "Please type the address for delivery \n").title() delv_method = input( "Please add the delivery method \n").title() status = input( "Please enter the status of the order \n").title() order.append({ 'Name': name, 'Address': address, 'Courier': delv_method, 'Status': status }) save_orders(order) module_print.read_orders() # Have to call save_lists to save it to the file # add_new_object(name, courier) module_save.save_lists('courier.txt', courier) # save_orders(order) choice_order_menu = module_menus.order_menu() elif choice_order_menu == "3": os.system("clear") # print key and values from dictionary on different lines module_print.read_orders() # select key to delete from dictionary, use title for capitalize input select_order = input("Please select a order to delete \n") try: # del order[index] for index, item in enumerate(order): if select_order in item.values(): del order[index] save_orders(order) delete_lists("courier.txt", select_order) print( f" {select_order} has been removed from the list") module_print.read_orders() choice_order_menu = module_menus.order_menu() except KeyError: print(f"order selected {select_order} does not exist") choice_order_menu = module_menus.order_menu() elif choice_order_menu == "4": os.system("clear") else: os.system("clear") print("Option selected is invalid") choice_order_menu = module_menus.order_menu() os.system("clear") choice_main_menu = module_menus.main_menu()