def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    list_options = [
        "1. Add new record to table",
        "2. Remove a record with a given id from the table",
        "3. Update specified record in the table",
        "4. Which items have not exceeded their durability yet?",
        "5. What are the average durability times for each manufacturer?"
    ]

    program_works = True

    while program_works:
        table = inventory.get_table()
        title_list = [
            "ID", "NAME", "MANUFACTURER", "PURCHASE YEAR", "DURABILITY"
        ]
        terminal_view.print_table(table, title_list)

        answer = terminal_view.get_choice(list_options)

        if answer == "1":
            record = terminal_view.get_inputs([
                "ID: ", "Name: ", "Manufacturer: ", "Purchase year: ",
                "Durability: "
            ], "Please provide information: \n")
            common.add(table, record)
            inventory.save_table(table)
        elif answer == "2":
            id_ = terminal_view.get_input("Please enter id number: ")
            common.remove(table, id_)
            inventory.save_table(table)
        elif answer == "3":
            id_ = terminal_view.get_input("Please enter id number: ")
            record = terminal_view.get_inputs([
                "Enter ID: ", "Name of item: ", "Manufacturer: ",
                "Year of purchase", "Durability year"
            ], "Please provide new information")
            common.update(table, id_, record)
            inventory.save_table(table)
        elif answer == "4":
            inventory.get_oldest_person(table)
        elif answer == "5":
            inventory.get_average_durability_by_manufacturers(table)
        elif answer == "0":
            program_works = False
        else:
            terminal_view.print_error_message(
                "There is no such choice. Choose from 1 to 5")
    return
예제 #2
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    table_headers = [
        'ID', 'Name', 'Manufacturer', 'Purchase Year', 'Durability'
    ]
    choice = None
    filename = 'model/inventory/inventory.csv'
    columns_headers = ['Name', 'Manufacturer', 'Purchase Year', 'Durability']
    ask_information = "Please provide your personal information"
    common.print_art(0)
    while choice != "0":
        choice = terminal_view.get_submenu_choice([
            'Add', 'Remove', 'Update',
            "Items that have not exceeded their durability yet",
            "Average durability by manufactirers"
        ])
        table = common.get_table_from_file(filename)

        if choice[0] == "1":
            common.clear_terminal()
            common.adding(table, table_headers, filename, columns_headers,
                          ask_information)
        elif choice[0] == "2":
            common.clear_terminal()
            common.removing(table, table_headers, id, filename)
        elif choice == "3":
            common.clear_terminal()
            common.updating(table, table_headers, id, filename,
                            columns_headers, ask_information)
        elif choice == "4":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            availible_items = inventory.get_available_items(table)
            terminal_view.print_result(
                "Items that have not exceeded their durability yet",
                availible_items)
        elif choice == "5":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            average_durability = inventory.get_average_durability_by_manufacturers(
                table)
            terminal_view.print_result("Average durability by manufactirers:",
                                       average_durability)
        elif int(choice) >= 6:
            common.clear_terminal()
            terminal_view.print_error_message("There is no such choice.")
예제 #3
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    # your code

    menu_inventory = [
        "Print inventory list", "Add to inventory list",
        "Remove form inventory list", "Update record in inventory list",
        "Available items", "Average durability"
    ]
    title = ["ID", "Name", "Manufacturer", "Purchase_year", "Durability"]
    title_del = ["Input ID: "]
    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(menu_inventory)

        if choice == "1":
            terminal_view.print_table(inventory.get_data(), title)

        if choice == "2":
            inventory.new_record(
                common.get_user_inp_record(
                    terminal_view.get_inputs(title[1:], "")),
                "model/inventory/inventory.csv")
        if choice == "3":
            inventory.delete_record(
                inventory.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                "model/inventory/inventory.csv")
        if choice == "4":
            inventory.update_record(
                inventory.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                terminal_view.get_inputs(title[1:], ""),
                "model/inventory/inventory.csv")
        if choice == "5":
            terminal_view.print_result(
                str(inventory.get_available_items(inventory.get_data())),
                "Available items: ")
        if choice == "6":
            terminal_view.print_result(
                str(
                    inventory.get_average_durability_by_manufacturers(
                        inventory.get_data())), "Oldest persons: ")
예제 #4
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """
    table = inventory.get_inventory_table_from_file()
    title_list = ["ID", "NAME", "Manufacturer".upper(), "Year".upper(), "Durability".upper()]
    options = ["View records",
               "Add record",
               "Remove record",
               "Update record",
               "Which items have not exceeded their durability yet?",
               "What are the average durability times for each manufacturer?"]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice_inner_menu(options, "Inventory manager")
        if choice == "1":
            terminal_view.print_table(table, title_list)
        elif choice == "2":
            data_input_not_correct = True
            while data_input_not_correct:
                record = terminal_view.get_inputs(title_list[1::],"Please provide new item data")
                if record[2].isdigit() and record[3].isdigit():
                    table = inventory.add(table, record)
                    data_input_not_correct = False
                else:
                    terminal_view.print_error_message("Year and durability should be natural numbers!")
        elif choice == "3":
            id_to_delete_table = terminal_view.get_inputs(["ID"],"Item to delete")
            id_to_delete = id_to_delete_table[0]
            table = inventory.remove(table, id_to_delete)
        elif choice == "4":
            records = terminal_view.get_inputs(title_list,"Edit item")
            record_id = records[0]
            table = inventory.update(table, record_id, records)
        elif choice == "5":
            available_items = inventory.get_available_items(table)
            terminal_view.print_table(available_items, title_list)
            #terminal_view.print_result(available_items, "Available items")
        elif choice == "6":
            average_durability = inventory.get_average_durability_by_manufacturers(table)
            list_from_dict = average_durability.items()
            dict_headers = ["MANUFACTURER","DURABILITY"]
            terminal_view.print_table(list_from_dict, dict_headers)
            # terminal_view.print_result(average_durability, "Average durability by manufacturer")
        elif choice != "0":
            terminal_view.print_error_message("There is no such choice.")
예제 #5
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """
    options = [
        'Add item', 'Edit item', 'Remove item',
        'Which items have not exceeded their durability yet',
        'What are the average durability times for each manufacturer'
    ]
    link_to_csv = 'model/inventory/inventory.csv'
    common_options = [
        'Name of item: ', 'Manufacturer: ', 'Year of purchase: ',
        'Years it can be used: '
    ]
    title_list = [
        "Id", "Name", "Manufacturer", "Year of purchase",
        "Years it can be used"
    ]
    choice = None
    dont_clear = False
    while choice != "0":
        if not dont_clear:
            os.system("clear")
            table = data_manager.get_table_from_file(link_to_csv)
            terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice_submenu(options)
        dont_clear = False
        if choice == "1":
            common.add(link_to_csv, common_options)
        elif choice == "2":
            common.update(link_to_csv, common_options)
        elif choice == "3":
            common.remove(link_to_csv)
        elif choice == "4":
            os.system("clear")
            table_to_print = inventory.get_available_items(table)
            terminal_view.print_table(table_to_print, labels)

            dont_clear = True
        elif choice == "5":
            terminal_view.print_result(
                inventory.get_average_durability_by_manufacturers(table),
                '\nWhat are the average durability times for each manufacturer: '
            )
            dont_clear = True
        else:
            terminal_view.print_error_message("There is no such choice.")
예제 #6
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """
    list_of_inventory = inventory.get_data_to_list()

    # your code
    options = ["Add new record",
               "Remove a record",
               "Update record",
               "Display available items",
               "Get average durability by manufacturers",
               "Print Table"]

    title_list = ["ID", "CONSOLA", "PRODUCENT", "YEAR", "DURABILITY"]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(options, "Back to main menu")
        if choice == "1":
            new_record = terminal_view.get_inputs(["Name: ", "Manufacturer: ", "Purchase year: ", "Durability: "], "Please enter value: ")
            new_record.insert(0, inventory.get_random_id(list_of_inventory))
            list_of_inventory = inventory.add(list_of_inventory, new_record)
        elif choice == "2":
            id_of_record_to_remove = ask_untill_correct(list_of_inventory)
            list_of_inventory = inventory.remove(list_of_inventory, common.check_id_by_number(list_of_inventory, int(id_of_record_to_remove)))
        elif choice == "3":
            id_of_record_to_update = ask_untill_correct(list_of_inventory)
            updated_record = terminal_view.get_inputs(["Name: ", "Manufacturer: ", "Purchase year: ", "Durability: "], "Please enter value: ")
            list_of_inventory = inventory.update(list_of_inventory, common.check_id_by_number(list_of_inventory, int(id_of_record_to_update)), updated_record)
        elif choice == "4":
            available_items = inventory.get_available_items(list_of_inventory)
            terminal_view.print_result(available_items, "Available items")
        elif choice == "5":
            average_durability = inventory.get_average_durability_by_manufacturers(list_of_inventory)
            terminal_view.print_result(average_durability, "Average durability by manufacturers")
        elif choice == "6":
            terminal_view.print_table(list_of_inventory, title_list)
        elif choice == "0":
            inventory.export_list_to_file(list_of_inventory)
        else:
            terminal_view.print_error_message("There is no such choice.")
def run():
    """
	Starts this module and displays its menu.
	* User can access default special features from here.
	* User can go back to main menu from here.

	Returns:
		None
	"""

    list_options = [
        'Inventory', 'Show all data', 'Add', 'Remove', 'Update',
        'Get available items', 'Get average durability by manufacturers',
        'Exit to main menu'
    ]
    list_labels = [['Name of console', str], ['Manufacturer', str],
                   ['Purchase year', "year"], ['Durability', "durability"]]
    data_file = "model/inventory/inventory.csv"
    crud_module = inventory
    while True:
        table = data_manager.get_table_from_file(data_file)
        max_id = len(table)
        user_choice = terminal_view.get_choice(list_options)
        if user_choice in ['1', '2', '3', '4']:
            make_crud(crud_module, list_labels, list_options, max_id, table,
                      user_choice)
        elif user_choice == '5':
            print(bcolors.WARNING + bcolors.BOLD)
            terminal_view.print_table(inventory.get_available_items(table),
                                      list_labels)
            print(bcolors.ENDC)
        elif user_choice == '6':
            terminal_view.print_result(
                inventory.get_average_durability_by_manufacturers(table),
                'Average durability by manufactures')
        elif user_choice == '0':
            break
        else:
            terminal_view.print_error_message("There is no such choice.")
 def test_get_average_durability_by_manufacturers(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected = {"Sony": 3.5, "Microsoft": 4, "Nintendo": 3.25}
     result = inventory.get_average_durability_by_manufacturers(table)
     self.assertEqual(result, expected)
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    title = "Inventory manager"
    options = [
        "Add item", "Remove item", "Update item",
        "Show items that have not exceeded their durability",
        "Show average durability times for each manufacturer"
    ]
    exit_message = "Back to main menu"

    title_list = [['Product'], ['Manufacturer'], ['Purchase year'],
                  ['Durability']]

    data_file = "model/inventory/inventory.csv"
    table = data_manager.get_table_from_file(data_file)
    terminal_view.print_table(table, title_list)

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(title, options, exit_message)
        if choice == "1":
            record = []
            index = 0
            inputs = terminal_view.get_inputs(title_list, title)
            for i in inputs:
                record.insert(index, i)
                index += 1
            inventory.add(table, record)
            data_manager.write_table_to_file(data_file, table)
            terminal_view.print_table(table, title_list)

        elif choice == "2":
            user_input = terminal_view.get_inputs(["Enter ID: "], "")
            inventory.remove(table, user_input[0])
            terminal_view.print_table(table, title_list)
        elif choice == "3":
            record = []
            index = 0
            user_input = terminal_view.get_inputs(["Enter ID: "], "")
            inputs = terminal_view.get_inputs(title_list, title)
            for i in inputs:
                record.insert(index, i)
                index += 1
            inventory.update(table, user_input[0], record)
            terminal_view.print_table(table, title_list)
        elif choice == "4":
            terminal_view.print_result(inventory.get_available_items(table),
                                       "Available items")
        elif choice == "5":
            terminal_view.print_result(
                inventory.get_average_durability_by_manufacturers(table),
                "Average durability by manufacturers")
        else:
            terminal_view.print_error_message("You have chosen back to menu.")
예제 #10
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    common.clear()
    title = 'Inventory menu'
    options = [
        "Add new record to table",
        "Remove a record with a given id from the table.",
        "Updates specified record in the table.",
        "Which items have not exceeded their durability yet?",
        "What are the average durability times for each manufacturer?"
    ]
    exit_message = "Back to main menu"
    title_list = ["ID", "NAME", "MANUFACTURER", "PURCHASE YEAR", 'DURABILITY']
    table = inventory.data_manager.get_table_from_file(
        'model/inventory/inventory.csv')

    choice = None

    while choice != "0":
        terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice(title, options, exit_message)
        if choice == "1":
            record = terminal_view.get_inputs(
                title_list, 'Please add following informations :', table)
            updated_table = inventory.add(table, record)
            inventory.data_manager.write_table_to_file(
                'model/inventory/inventory.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "2":
            id_ = terminal_view.get_inputs(['Id'],
                                           'Please give ID to remove :', table)
            updated_table = inventory.remove(table, id_)
            inventory.data_manager.write_table_to_file(
                'model/inventory/inventory.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "3":
            id_ = terminal_view.get_inputs(['Id'],
                                           'Please give ID of changed line :',
                                           table)
            record = terminal_view.get_inputs(
                title_list, 'Please add following informations :', table)
            updated_table = inventory.update(table, id_, record)
            inventory.data_manager.write_table_to_file(
                'model/inventory/inventory.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "4":
            label = "The items that have not exceeded their durability yet: "
            result = inventory.get_available_items(table)
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice == "5":
            label = "What are the average durability times for each manufacturer?"
            result = inventory.get_average_durability_by_manufacturers(table)
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice != 0:
            terminal_view.print_error_message("There is no such choice.")
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    title_list = [
        "* ID", "* Name of item", "* Manufacturer", "* Year of purchase",
        "* Years it can be used"
    ]

    options = [
        "Add new record to table",
        "Remove a record with a given id from the table",
        "Update specified record in the table",
        "Items that have not exceeded their durability yet",
        "Average durability for each manufacturer", "Print table"
    ]
    os.system('clear')
    file = "model/inventory/inventory.csv"
    choice = None
    while choice != "0":
        terminal_view.print_menu("What do you want to do: ", options,
                                 "Back to main menu")
        choice = terminal_view.get_choice(options)
        if choice == "1":
            common.all_add(title_list, file)
        elif choice == "2":
            common.all_remove(title_list, file)
        elif choice == "3":
            common.all_updates(title_list, file)
        elif choice == "4":
            file_name = common.get_input("Choose a file: ")
            if file_name == "":
                file_name = file
            table = common.get_table_from_file(file_name)
            items_with_available_durability = inventory.get_available_items(
                table)
            os.system("clear")
            print("Items that have not exceeded their durability:\n",
                  items_with_available_durability)
            common.waiting()
            os.system("clear")
        elif choice == "5":
            file_name = common.get_input("Choose a file: ")
            if file_name == "":
                file_name = "model/store/games.csv"
            table = common.get_table_from_file(file_name)
            average_durability = inventory.get_average_durability_by_manufacturers(
                table)
            os.system("clear")
            print("Average durability times for each manufacturer:\n",
                  average_durability)
            common.waiting()
            os.system("clear")
        elif choice == "6":
            common.all_print_table(title_list, file)

        else:
            if choice != "0":
                terminal_view.print_error_message("There is no such choice.")