Beispiel #1
0
def update_transaction():
    view.clear_console()
    transactions = sales.read()
    view.print_table(transactions, sales.HEADERS, "Transactions: ")

    is_correct_value = False
    while not is_correct_value:
        transaction_id = view.get_input('Provide a valid transactions id to update profile: ')
        try:
            transaction_id = int(transaction_id)
            if transaction_id > 0 and transaction_id <= len(transactions):
                is_correct_value = True
                transaction_id = int(transaction_id) - 1
            else:
                view.print_error_message("Incorrect value. Try again.")
        except:
            view.print_error_message("Incorrect value. Try again.")

    transaction_to_change = transactions.pop(transaction_id)
    want_change_next_value = True
    while want_change_next_value:
        index = view.get_input(
            'Specify which value you are attempting to change \n1 for Customer id, 2 for Product, 3 for Price, 4 for Date: ')
        choices = ['1', '2', '3', '4']
        while index not in choices:
            view.print_error_message("Incorrect value. Try again!")
            index = view.get_input(
                'Specify which value you are attempting to change \n1 for Customer id, 2 for Product, 3 for Price, 4 for Date: ')
        transaction_to_change[int(index)] = view.get_input("Provide new value: ")
        want_change_next_value = view.get_yes_or_no("Would you like to change another value? ")
    transactions.append(transaction_to_change)
    sales.create(transactions)
def get_updated_employee_data(employee, headers):
    index = 1

    while index < len(employee):
        ask_label = f"Would you like to edit {headers[index]}? "
        new_data_label = f"Provide new {headers[index]}: "
        decision = view.get_yes_or_no(ask_label)
        if decision:
            employee[index] = view.get_input(new_data_label)
            employee[index] = accept_data(employee[index], new_data_label)
        index += 1
    return employee
def get_updated_customer_data(customer, headers):
    index = 1

    while index < len(customer):
        ask_label = view.color_sentence(
            Fore.GREEN, f"Would you like to edit {headers[index]}? ")
        new_data_label = view.color_sentence(
            Fore.GREEN, f"Provide new {headers[index]}: ")
        decision = view.get_yes_or_no(ask_label)
        if decision:
            customer[index] = view.get_input(new_data_label)
            customer[index] = accept_data(customer[index], new_data_label)
        index += 1
    return customer
def get_customer_data():

    name_label = view.color_sentence(Fore.GREEN, "Provide customer name: ")
    name = view.get_input(name_label)
    if name.lower() == BACK_WORD:
        return
    name = accept_data(name, name_label)

    email_label = view.color_sentence(Fore.GREEN, "Provide customer email: ")
    email = view.get_input(email_label)
    if email.lower() == BACK_WORD:
        return
    email = accept_data(email, email_label)

    subscribe_label = view.color_sentence(Fore.GREEN,
                                          "Is the customer a subscriber? ")
    subscribed = view.get_yes_or_no(subscribe_label)
    subscribed = accept_data(subscribed, subscribe_label)
    subscribed = "1" if subscribed else '0'

    return [name, email, subscribed]
def accept_data(data, label):
    while not view.get_yes_or_no(f"Is the value \"{data}\" correct? "):
        data = view.get_input(label)
    return data
def accept_data(data, label):
    while not view.get_yes_or_no(
            view.color_sentence(Fore.GREEN,
                                f"Is the value \"{data}\" correct? ")):
        data = view.get_input(label)
    return data