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. What is the id of the item that was sold for the lowest price?", 
                    "5. Which items are sold between two given dates?"]
    
    program_works = True

    while program_works:
        table = sales.get_table()  
        title_list = ["ID", "TITLE", "PRICE","MONTH","DAY","YEAR"]
        terminal_view.print_table(table, title_list)

        answer = terminal_view.get_choice(list_options)

        if answer == "1":
            record = terminal_view.get_inputs(["ID: ","Title of the game sold: ","The actual sale price in USD: ","Month of the sale: ","Day of the sale: ","Year of the sale: "],"Please provide information: \n")
            common.add(table, record)
            sales.save_table(table)
        elif answer == "2":
            id_ = terminal_view.get_input("Please enter id number: ")
            common.remove(table, id_)
            sales.save_table(table)
        elif answer == "3":
            id_ = terminal_view.get_input("Please enter id number: ")
            record = terminal_view.get_inputs(["ID: ","Title of the game sold: ","The actual sale price in USD: ","Month of the sale: ","Day of the sale: ","Year of the sale: "],"Please provide information: \n")
            common.update(table, id_, record)
            sales.save_table(table)
        elif answer == "4":
            sales.get_oldest_person(table)
        elif answer == "5":
            sales.get_items_sold_between(table, month_from, day_from, year_from, month_to, day_to, year_to)
        elif answer == "0":
            program_works = False
        else:
            terminal_view.print_error_message("There is no such choice. Choose from 1 to 5")
    return 
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', 'Title', 'Price', 'Month', 'Day', 'Year']
    choice = None
    filename = 'model/sales/sales.csv'
    columns_headers = ['Title', 'Price', 'Month', 'Day', 'Year']
    ask_information = "Please provide your personal information"

    common.print_art(0)
    while choice != "0":
        choice = terminal_view.get_submenu_choice([
            'Add', 'Remove', 'Update', 'Check lowest price item',
            'Check items sold between dates'
        ])
        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)
            sales_id = sales.get_lowest_price_item_id(table)
            terminal_view.print_result("The lowest price item id is", sales_id)
        elif choice == "5":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            date_list = terminal_view.get_inputs([
                'month_from', 'day_from', 'year_from', 'month_to', 'day_to',
                'year_to'
            ], "Please provide dates information: ")
            sold_list = sales.get_items_sold_between(table, int(date_list[0]),
                                                     int(date_list[1]),
                                                     int(date_list[2]),
                                                     int(date_list[3]),
                                                     int(date_list[4]),
                                                     int(date_list[5]))
            terminal_view.print_result(
                "The items sold between given dates are:", sold_list)
        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
	"""
	
	list_options = [
		'Sales',
		'Show all data',
		'Add',
		'Remove',
		'Update',
		'Get lowest price item id',
		'Get items sold between',
		'Exit to main menu'
	]
	data_file = "model/sales/sales.csv"
	crud_module = sales
	while True:
		table = data_manager.get_table_from_file(data_file)
		max_id = len(table)
		list_labels = [
			['Title', str],
			['Price', int],
			['Month', 'month'],
			['Day', 'day'],
			['Year', 'year'],
			['Customer', str]
		]
		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':
			result = sales.get_lowest_price_item_id(table)
			terminal_view.print_result(result, "Lowest price item ID")
		elif user_choice == '6':
			inputs_labels_between = [
				['Date from', 'date'],
				['Date to', 'date'],
			]
			inputs = terminal_view.get_inputs(['must'] + inputs_labels_between, 'Date from to')
			inputs = [int(item) for item in inputs]
			result = sales.get_items_sold_between(table, *inputs)
			print(common.bcolors.WARNING + common.bcolors.BOLD)
			terminal_view.os.system('clear')
			if common.check_if_empty(result):
				terminal_view.print_table(result, list_labels)
			print(common.bcolors.ENDC)
		
		elif user_choice == '0':
			break
		
		else:
			terminal_view.print_error_message("There is no such choice.")
def run():
    options = ["Add", "Remove", "Update", "Lowest price item ID", "Items sold between", "Game title by ID", "All the Customer\'s IDs", "The sales of each customer", "The sales of each customer", "The number of sales of each customer", "The number of sales of each customer: "]
    common_options = ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "]
    link_for_csv = "model/sales/sales.csv"
    title_list = ["ID", "Title", "Price", "Month", "Day", "Year", "Customer ID"]
    choice = None
    dont_clear = False
    while choice != '0':
        if not dont_clear:
            os.system("clear")
            table = data_manager.get_table_from_file(link_for_csv)
            terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice_submenu(options)
        dont_clear = False
        if choice == '1':
            common.add(link_for_csv, common_options)
        elif choice == '2':
            common.remove(link_for_csv)
        elif choice == '3':
            common.update(link_for_csv, common_options)
        elif choice == '4':
            lowest_price = sales.get_lowest_price_item_id(table)
            terminal_view.print_result(lowest_price, 'Lowest price game is: ')
            dont_clear = True
        elif choice == '5':
            dates_to_input = ['From month: ', 'From day: ', 'From year: ', 'To month:', 'To day: ', "To year: "]
            inputs = terminal_view.get_input(dates_to_input, "Please input appropriate data.")
            answer = sales.get_items_sold_between(table, int(inputs[0]), int(inputs[1]), int(inputs[2]), int(inputs[3]),
                                                  int(inputs[4]), int(inputs[5]))
            terminal_view.print_table(answer, title_list)
            dont_clear = True
        elif choice == '6':
            dates_to_input = 'Input ID: '
            inputs = terminal_view.get_input(dates_to_input, 'Please input appropriate data.')
            answer = sales.get_title_by_id(inputs)
            terminal_view.print_result(answer, 'Game title is: ')
            dont_clear = True
        elif choice == "7":
            terminal_view.print_result(sales.get_all_customer_ids_from_table(table), 'All the Customer\'s ID: ')
            dont_clear = True
        elif choice == "8":
            terminal_view.print_result(sales.get_all_sales_ids_for_customer_ids(), "The sales of each customer: ")
            dont_clear = True
        elif choice == "9":
            terminal_view.print_result(sales.get_all_sales_ids_for_customer_ids_form_table(table), "The sales of each customer: ")
            dont_clear = True
        elif choice == "10":
            terminal_view.print_result(sales.get_num_of_sales_per_customer_ids(), "The number of sales of each customer: ")
            dont_clear = True
        elif choice == "11":
            terminal_view.print_result(sales.get_num_of_sales_per_customer_ids_from_table(table), "The number of sales of each customer: ")
            dont_clear = True
 def test_get_items_sold_between(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected = get_item_sold_between_dates()
     result = sales.get_items_sold_between(table, 2, 12, 2016, 7, 6, 2016)
     compare_lists(self, expected, result)
def run():
    options = [
        "Add", "Remove", "Update", "Lowest price item ID",
        "Items sold between", "Game title by ID", "All the Customer\'s IDs",
        "Item that was sold most recently", "The sales of each customer",
        "The number of sales of each customer", "Sum of prices for given IDs",
        "Customer ID for Sale ID"
    ]
    common_options = ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "]
    file = "model/sales/sales.csv"
    title_list = [
        "ID", "Title", "Price", "Month", "Day", "Year", "Customer ID"
    ]
    choice = None
    terminal_clear = False
    while choice != '0':
        if not terminal_clear:
            os.system("clear")
            table = common.clear_instructions(file, title_list)
        choice = terminal_view.get_choice_submenu(options)
        terminal_clear = False
        if choice == '1':
            sales.add(common_options)
        elif choice == '2':
            sales.remove()
        elif choice == '3':
            sales.update(common_options)
        elif choice == '4':
            lowest_price = sales.get_lowest_price_item_id(table)
            terminal_view.print_result(lowest_price, 'Lowest price game is: ')
            terminal_clear = True
        elif choice == '5':
            dates_to_input = [
                'From month: ', 'From day: ', 'From year: ', 'To month:',
                'To day: ', "To year: "
            ]
            inputs = terminal_view.get_input(dates_to_input,
                                             "Please input appropriate data.")
            answer = sales.get_items_sold_between(table, int(inputs[0]),
                                                  int(inputs[1]),
                                                  int(inputs[2]),
                                                  int(inputs[3]),
                                                  int(inputs[4]),
                                                  int(inputs[5]))
            terminal_view.print_table(answer, title_list)
            terminal_clear = True
        elif choice == '6':
            dates_to_input = 'Input ID: '
            inputs = terminal_view.get_input(dates_to_input,
                                             'Please input appropriate Id.')
            answer = sales.get_title_by_id(inputs)
            terminal_view.print_result(answer + '\n', 'Game title is: \n')
            terminal_clear = True
        elif choice == "7":
            terminal_view.print_result(
                sales.get_all_customer_ids_from_table(table),
                'All the Customer\'s ID: ')
            terminal_clear = True
        elif choice == "8":
            terminal_view.print_result(sales.get_item_id_sold_last(),
                                       'Item that was sold most recently')
            terminal_clear = True
        elif choice == "9":
            terminal_view.print_result(
                sales.get_all_sales_ids_for_customer_ids_form_table(table),
                "The sales of each customer: ")
            terminal_clear = True
        elif choice == "10":
            terminal_view.print_result(
                sales.get_num_of_sales_per_customer_ids_from_table(table),
                "The number of sales of each customer: ")
            terminal_clear = True
        elif choice == "11":
            ids_amount = terminal_view.get_input(
                "Amount of IDs: ", "How many IDs would you like to sum up?")
            ids = []
            for i in range(int(ids_amount)):
                ids.append("Sale ID: ")
            inputs = terminal_view.get_inputs(ids, "Please provide an ID")
            result = sales.get_the_sum_of_prices_from_table(table, inputs)
            terminal_view.print_result(result, "Sum of prices for given IDs: ")
            terminal_clear = True
        elif choice == "12":
            sale_id = terminal_view.get_input("Sale ID: ",
                                              "Please provide sale ID")
            result = sales.get_customer_id_by_sale_id_from_table(
                table, sale_id)
            terminal_view.print_result(
                result, "Customer ID for Sale ID you provided: ")
            terminal_clear = True
        else:
            terminal_view.print_error_message(
                "There is no such choice, please try again")
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_games = sales.get_data_to_list()

    # your code
    options = [
        "Add new record", "Remove a record", "Update record",
        "Id of the item that was sold for the lowest price",
        "Items are sold between two given dates", "Print table"
    ]

    choice = None

    title_list = ["ID", "TITLE", "SALES", "MONTH", "DAY", "YEAR"]

    while choice != "0":
        # terminal_view.print_table(table, title_list
        choice = terminal_view.get_choice(options, "Back to main menu")
        if choice == "1":
            new_record = terminal_view.get_inputs(
                ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "],
                "Please enter value: ")
            new_record.insert(0, sales.get_random_id(list_of_games))
            list_of_games = sales.add(list_of_games, new_record)
        elif choice == "2":
            id_of_record_to_remove = ask_untill_correct(list_of_games)
            list_of_games = sales.remove(
                list_of_games,
                common.check_id_by_number(list_of_games,
                                          int(id_of_record_to_remove)))
        elif choice == "3":
            id_of_record_to_update = ask_untill_correct(list_of_games)
            updated_record = terminal_view.get_inputs(
                ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "],
                "Please enter value: ")
            list_of_games = sales.update(
                list_of_games,
                common.check_id_by_number(list_of_games,
                                          int(id_of_record_to_update)),
                updated_record)
        elif choice == "4":
            label = "What is the id of the item that was sold for the lowest price?"
            result = str(sales.get_lowest_price_item_id(list_of_games))
            terminal_view.print_result(result, label)
        elif choice == "5":
            label = "Which items are sold between two given dates? (from_date < sale_date < to_date)"
            month_from = terminal_view.get_inputs(
                ['Month from'], "Please give starting month.")
            day_from = terminal_view.get_inputs(['Day from'],
                                                "Please give starting day.")
            year_from = terminal_view.get_inputs(['Year from'],
                                                 "Please give starting year.")
            month_to = terminal_view.get_inputs(['Month to'],
                                                "Please give ending month.")
            day_to = terminal_view.get_inputs(['Day to'],
                                              "Please give ending day.")
            year_to = terminal_view.get_inputs(['Year to'],
                                               "Please give ending year.")
            month_from = int(month_from[0])
            day_from = int(day_from[0])
            year_from = int(year_from[0])
            month_to = int(month_to[0])
            day_to = int(day_to[0])
            year_to = int(year_to[0])
            result = (sales.get_items_sold_between(list_of_games, month_from,
                                                   day_from, year_from,
                                                   month_to, day_to, year_to))
            terminal_view.print_result(result, label)
        elif choice == "6":
            terminal_view.print_table(list_of_games, title_list)
        elif choice == "0":
            sales.export_list_to_file(list_of_games)
        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
    """
    def get_user_inp():
        inp_list = []
        title_list = [
            "month_from: ", "day_from: ", "year_from: ", "month_to: ",
            "day_to: ", "year_to: "
        ]
        try:
            user_inp = terminal_view.get_inputs(title_list, "")
            val = user_inp
            inp_list = list(map(int, val))
        except ValueError:
            inp_list.clear()
            return get_user_inp()
        return inp_list

    #  def get_user_inp_record(title_list):
    #     inp_list = []
    #     user_inp = terminal_view.get_inputs(title_list, "")
    #     val = user_inp
    #    print(val)
    #    return val

    # your code
    menu_sale = [
        "Print sale list", "Add to sale list", "Remove form sale list",
        "Update record in sale list", "Get ID lowest price item",
        "Get Item/s between date"
    ]
    title = ["ID", "Title", "Price", "Month", "Day", "Year"]
    title_del = ["Input ID: "]
    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(menu_sale)

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

        if choice == "2":
            sales.new_record(
                common.get_user_inp_record(
                    terminal_view.get_inputs(title[1:], "")),
                "model/sales/sales.csv")

        if choice == "3":
            sales.delete_record(
                sales.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                "model/sales/sales.csv")

        if choice == "4":
            sales.update_record(
                sales.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                terminal_view.get_inputs(title[1:], ""),
                "model/sales/sales.csv")

        if choice == "5":
            terminal_view.print_result(
                sales.get_lowest_price_item_id(sales.get_data()),
                'Id of the item sold the cheapest')
        if choice == "6":
            user_input_list = get_user_inp()
            terminal_view.print_table(
                sales.get_items_sold_between(
                    sales.get_data(), user_input_list[0], user_input_list[1],
                    user_input_list[2], user_input_list[3], user_input_list[4],
                    user_input_list[5]), title)
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 = 'Sales menu'
    options = [
        "Add new record to table",
        "Remove a record with a given id from the table.",
        "Updates specified record in the table.",
        "What is the id of the item that was sold for the lowest price?",
        "Which items are sold between two given dates? (from_date < sale_date < to_date)"
    ]
    exit_message = "Back to main menu"
    title_list = ["ID", "TITLE", "PRICE", "MONTH", 'DAY', 'YEAR']
    table = sales.data_manager.get_table_from_file('model/sales/sales.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 = sales.add(table, record)
            sales.data_manager.write_table_to_file('model/sales/sales.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 = sales.remove(table, id_)
            sales.data_manager.write_table_to_file('model/sales/sales.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 = sales.update(table, id_, record)
            sales.data_manager.write_table_to_file('model/sales/sales.csv',
                                                   updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "4":
            label = "What is the id of the item that was sold for the lowest price?"
            result = str(sales.get_lowest_price_item_id(table))
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice == "5":
            label = "Which items are sold between two given dates? (from_date < sale_date < to_date)"
            month_from = terminal_view.get_inputs(
                ['Month from'], "Please give starting month.")
            day_from = terminal_view.get_inputs(['Day from'],
                                                "Please give starting day.")
            year_from = terminal_view.get_inputs(['Year from'],
                                                 "Please give starting year.")
            month_to = terminal_view.get_inputs(['Month to'],
                                                "Please give ending month.")
            day_to = terminal_view.get_inputs(['Day to'],
                                              "Please give ending day.")
            year_to = terminal_view.get_inputs(['Year to'],
                                               "Please give ending year.")
            month_from = int(month_from[0])
            day_from = int(day_from[0])
            year_from = int(year_from[0])
            month_to = int(month_to[0])
            day_to = int(day_to[0])
            year_to = int(year_to[0])
            result = str(
                sales.get_items_sold_between(table, month_from, day_from,
                                             year_from, month_to, day_to,
                                             year_to))
            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
    """

    table = sales.get_sales_table_from_file()
    title_list = ["ID", "Title","Price", "Month", "Day", "Year"]
    options = ["View records",
               "Add record",
               "Remove record",
               "Update record",
               "What is the id of the item that was sold for the lowest price?",
               "Which items are sold between two given dates?"]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice_inner_menu(options, "Sales manager")
        if choice == "1":
            terminal_view.print_table(table, title_list)
        elif choice == "2":
            record = terminal_view.get_inputs(title_list[1::],"Please provide new item data")
            table = sales.add(table, record)
        elif choice == "3":
            id_to_delete_table = terminal_view.get_inputs(["ID"],"Item to delete")
            id_to_delete = id_to_delete_table[0]
            table = sales.remove(table, id_to_delete)
        elif choice == "4":
            records = terminal_view.get_inputs(title_list,"Edit item")
            record_id = records[0]
            table = sales.update(table, record_id, records)
        elif choice == "5":
            lowest_price = sales.get_lowest_price_item_id(table)
            description = ["ID of item that was sold for the lowest price:"]
            value = [[lowest_price]]
            terminal_view.print_table(value, description)
        elif choice == "6":
            day_from_input = terminal_view.get_inputs(["Day from"],"")
            while not day_from_input[0].isdigit():
                day_from_input = terminal_view.get_inputs(["Your input is not digit. Choose correct day from range 1-31"],"")
            while day_from_input[0].isdigit():
                while int(day_from_input[0]) > 31 or int(day_from_input[0]) < 1:
                    day_from_input = terminal_view.get_inputs(["Choose correct day from range 1-31"],"")
                    while not day_from_input[0].isdigit():
                        day_from_input = terminal_view.get_inputs(["Your input is not digit. Choose correct day from range 1-31"],"")
                break
            day_from = day_from_input[0]
            
            month_from_input = terminal_view.get_inputs(["Month from"],"")
            while not month_from_input[0].isdigit():
                month_from_input = terminal_view.get_inputs(["Your input is not digit. Choose correct month from range 1-12"],"")
            while month_from_input[0].isdigit():            
                while not int(month_from_input[0]) < 13 or not int(month_from_input[0]) > 0:
                    month_from_input = terminal_view.get_inputs(["Choose correct month from range 1-12"],"")   
                    while not month_from_input[0].isdigit():
                        month_from_input = terminal_view.get_inputs(["Your input is not digit. Choose correct month from range 1-12"],"")
                break 
            month_from = month_from_input[0]
            
            year_from_input = terminal_view.get_inputs(["Year from"],"")
            while not year_from_input[0].isdigit():
                year_from_input = terminal_view.get_inputs(["Your input is not digit. Choose correct year"],"")
            while year_from_input[0].isdigit():
                while not int(year_from_input[0]) > 0:
                    year_from_input = terminal_view.get_inputs(["Choose correct year"],"")
                    while not year_from_input[0].isdigit():
                        year_from_input = terminal_view.get_inputs(["Your input is not digit. Choose correct year"],"")
                break
            year_from = year_from_input[0]
            
            day_to_input = terminal_view.get_inputs(["Day to"],"")
            while not day_to_input[0].isdigit():
                day_to_input = terminal_view.get_inputs(["Your input is not digit. Choose correct day from range 1-31"],"")
            while day_to_input[0].isdigit():
                while not int(day_to_input[0]) < 32 or not int(day_to_input[0]) > 0:
                    day_to_input = terminal_view.get_inputs(["Choose correct day from range 1-31"],"")
                    while not day_to_input[0].isdigit():
                        day_to_input = terminal_view.get_inputs(["Your input is not digit. Choose correct day from range 1-31"],"")
                break
            day_to = day_to_input[0]
            
            month_to_input = terminal_view.get_inputs(["Month to"],"")
            while not month_to_input[0].isdigit():
                month_to_input = terminal_view.get_inputs(["Your input is not digit. Choose correct month from range 1-12"],"") 
            while month_to_input[0].isdigit():
                while not int(month_to_input[0]) < 13 or not int(month_to_input[0]) > 0:
                    month_to_input = terminal_view.get_inputs(["Choose correct month from range 1-12"],"")
                    while not month_to_input[0].isdigit():
                        month_to_input = terminal_view.get_inputs(["Your input is not digit. Choose correct month from range 1-12"],"") 
                break
            month_to = month_to_input[0]
            
            year_to_input = terminal_view.get_inputs(["Year to"],"")
            while not year_to_input[0].isdigit():
                year_to_input = terminal_view.get_inputs(["Your input is not digit. Choose correct year"],"")
            while year_to_input[0].isdigit():
                while not int(year_to_input[0]) > 0 or not int(year_to_input[0]) > int(year_from):
                    year_to_input = terminal_view.get_inputs(["You can't choose year before 'Year from' value. Put correct year"],"")
                    while not year_to_input[0].isdigit():
                        year_to_input = terminal_view.get_inputs(["Your input is not digit. Choose correct year"],"")
                break
            year_to = year_to_input[0]

            items_sold_by_date = sales.get_items_sold_between(table, month_from, day_from, year_from, month_to, day_to, year_to)
            terminal_view.print_table(items_sold_by_date,title_list)
        elif choice != "0":
            terminal_view.print_error_message("There is no such choice.")
Пример #11
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
    """

    title = "Sales manager"
    options = [
        "Add item", "Remove item", "Update item",
        "Show ID of item sold for lowest price",
        "Show item sold between certain dates"
    ]
    exit_message = "Back to main menu"

    title_list = [['Title'], ['Price'], ['Month'], ['Day'], ['Year']]

    data_file = "model/sales/sales.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
            sales.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: "], "")
            sales.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
            sales.update(table, user_input[0], record)
            terminal_view.print_table(table, title_list)
        elif choice == "4":
            terminal_view.print_result(sales.get_lowest_price_item_id(table),
                                       "ID of item with lowest price")
        elif choice == "5":
            month_from = terminal_view.get_inputs(["Month from:"], "")
            day_from = terminal_view.get_inputs(["Day from:"], "")
            year_from = terminal_view.get_inputs(["Year from:"], "")
            month_to = terminal_view.get_inputs(["Month to:"], "")
            day_to = terminal_view.get_inputs(["Day to:"], "")
            year_to = terminal_view.get_inputs(["Year to:"], "")

            terminal_view.print_result(
                sales.get_items_sold_between(table, month_from[0], day_from[0],
                                             year_from[0], month_to[0],
                                             day_to[0], year_to[0]),
                "Items sold in cetrain time")
        else:
            terminal_view.print_error_message("You have chosen back to menu.")