|
| 1 | +''' |
| 2 | +Launches the user interface for the inventory management system |
| 3 | +''' |
| 4 | +import sys |
| 5 | +from inventory_management import market_prices |
| 6 | +from inventory_management import inventory_class |
| 7 | +from inventory_management import furniture_class |
| 8 | +from inventory_management import electric_appliances_class as ea |
| 9 | + |
| 10 | + |
| 11 | +def main_menu(user_prompt=None): |
| 12 | + ''' |
| 13 | + produces main menu for user interface |
| 14 | + :param user_prompt: |
| 15 | + :return: |
| 16 | + ''' |
| 17 | + valid_prompts = {"1": add_new_item, |
| 18 | + "2": item_info, |
| 19 | + "q": exit_program} |
| 20 | + options = list(valid_prompts.keys()) |
| 21 | + |
| 22 | + while user_prompt not in valid_prompts: |
| 23 | + options_str = ("{}" + ", {}" * (len(options)-1)).format(*options) |
| 24 | + print(f"Please choose from the following options ({options_str}):") |
| 25 | + print("1. Add a new item to the inventory") |
| 26 | + print("2. Get item information") |
| 27 | + print("q. Quit") |
| 28 | + user_prompt = input(">") |
| 29 | + return valid_prompts.get(user_prompt) |
| 30 | + |
| 31 | + |
| 32 | +def get_price(item_code): |
| 33 | + ''' |
| 34 | + prints 'Get price' |
| 35 | + :return: |
| 36 | + ''' |
| 37 | + |
| 38 | + price = FULL_INVENTORY[item_code]['rental_price'] |
| 39 | + |
| 40 | + return price |
| 41 | + |
| 42 | + |
| 43 | +def add_new_item(): |
| 44 | + ''' |
| 45 | + add new inventory item |
| 46 | + :return: |
| 47 | + ''' |
| 48 | + |
| 49 | + item_code = input("Enter item code: ") |
| 50 | + item_description = input("Enter item description: ") |
| 51 | + item_rental_price = input("Enter item rental price: ") |
| 52 | + |
| 53 | + # Get price from the market prices module |
| 54 | + item_price = market_prices.get_latest_prices() |
| 55 | + |
| 56 | + is_furniture = input("Is this item a piece of furniture? (Y/N): ") |
| 57 | + if is_furniture.lower() == "y": |
| 58 | + item_material = input("Enter item material: ") |
| 59 | + item_size = input("Enter item size (S,M,L,XL): ") |
| 60 | + new_item = furniture_class.Furniture( |
| 61 | + item_code, item_description, item_price, |
| 62 | + item_rental_price, item_material, item_size) |
| 63 | + else: |
| 64 | + is_electric_appliance = input( |
| 65 | + "Is this item an electric appliance? (Y/N): ") |
| 66 | + if is_electric_appliance.lower() == "y": |
| 67 | + item_brand = input("Enter item brand: ") |
| 68 | + item_voltage = input("Enter item voltage: ") |
| 69 | + new_item = ea.ElectricAppliances( |
| 70 | + item_code, item_description, item_price, |
| 71 | + item_rental_price, item_brand, item_voltage) |
| 72 | + else: |
| 73 | + new_item = inventory_class.Inventory( |
| 74 | + item_code, item_description, item_price, item_rental_price) |
| 75 | + FULL_INVENTORY[item_code] = new_item.return_as_dictionary() |
| 76 | + print("New inventory item added") |
| 77 | + return FULL_INVENTORY[item_code] |
| 78 | + |
| 79 | +def item_info(): |
| 80 | + ''' |
| 81 | + prints info for inventory item |
| 82 | + :return: |
| 83 | + ''' |
| 84 | + item_code = input("Enter item code: ") |
| 85 | + if item_code in FULL_INVENTORY: |
| 86 | + print_dict = FULL_INVENTORY[item_code] |
| 87 | + output = [] |
| 88 | + for key, value in print_dict.items(): |
| 89 | + print("{}:{}".format(key, value)) |
| 90 | + output.append(print_dict) |
| 91 | + else: |
| 92 | + print("Item not found in inventory") |
| 93 | + output = "Item not found in inventory" |
| 94 | + |
| 95 | + return output |
| 96 | + |
| 97 | + |
| 98 | +def exit_program(): |
| 99 | + ''' |
| 100 | + exits program |
| 101 | + :return: |
| 102 | + ''' |
| 103 | + sys.exit() |
| 104 | + |
| 105 | + |
| 106 | +FULL_INVENTORY = {} |
| 107 | + |
| 108 | +if __name__ == '__main__': |
| 109 | + |
| 110 | + while True: |
| 111 | + print(FULL_INVENTORY) |
| 112 | + main_menu()() |
| 113 | + input("Press Enter to continue...........") |
0 commit comments