Exemple #1
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.")
Exemple #2
0
def run():
    options = [
        "Display data as a table", "Add new data", "Remove data", "Update",
        "Which items have not exceeded their durability yet?",
        "What are the average durability times for each manufacturer?"
    ]
    choice = None
    while choice != "0":
        terminal_view.print_menu("Inventory menu ", options,
                                 "Go back to main menu")
        inputs = terminal_view.get_inputs(["Please enter a number: "], "")
        choice = inputs[0]
        table_titles = [
            "id", "name", "manufacturer", "Year of purchase", "durability"
        ]
        #reading data from file
        data_table = data_manager.get_table_from_file(
            "model/inventory/inventory.csv")
        if choice == "1":
            terminal_view.print_table(data_table, table_titles)
        elif choice == "2":
            table_titles.pop(0)
            inventory.add(data_table, table_titles)
        elif choice == "3":
            inventory.remove(data_table, get_user_id("remove"))
        elif choice == "4":
            inventory.update(data_table, get_user_id("update"),
                             common.get_user_record(table_titles[1:]))
        elif choice == "5":
            sales_controller.run()
        elif choice == "6":
            crm_controller.run()
        elif choice == "0":
            root_controller.run()
        else:
            terminal_view.print_error_message("There is no such choice.")
Exemple #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
    """
    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
    """

    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.")
Exemple #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
    """

    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.")