def list_customers(): view.clear_console() customers = crm.read() view.print_table(customers, crm.HEADERS, title='All customers:') view.wait_for_reaction() view.clear_console() display_menu()
def run(): options = [ "Print list", "Add record", "Update record", "Remove record", 'Transaction by employee', 'Transaction by customer' ] choice = None while choice != "0": choice = terminal_view.get_choice('SALES MENU', options) if choice == "1": # show list of all records terminal_view.print_table(sales_list, 'Sales list') elif choice == "2": # add record crm.create( sales_list, terminal_view.get_inputs(list_labels, 'Enter transaction data below:', ''), sales_file) elif choice == "3": # update record crm.update( sales_list, terminal_view.get_inputs(temp, 'Enter transaction ID to update: ', ''), terminal_view.get_inputs(list_labels[1:], 'Enter id, name or e-mail to update', sales_file), sales_file) elif choice == "4": # remove record crm.delete( sales_list, terminal_view.get_inputs(temp, 'Enter transaction ID to remove: ', ''), sales_file) elif choice == '5': terminal_view.print_result( crm.read(sales_list, terminal_view.get_inputs(temp, 'ID:', '')), '') elif choice == '6': terminal_view.print_result( crm.read(sales_list, terminal_view.get_inputs(temp, 'ID:', '')), '') crm.delete( sales_list, terminal_view.get_inputs(temp, 'Enter transaction ID to remove: ', ''), sales_file) else: terminal_view.print_error_message("There is no such choice.")
def test_fetch_record_by_id(self): table = data_manager.get_table_from_file(self.data_file) record_id_to_found = "vH34Jz#&" expected_record = [ "vH34Jz#&", "Royce Stager", "*****@*****.**", "1959-12-19", "1" ] actual_record = crm.read(table, record_id_to_found) self.assertListEqual(actual_record, expected_record)
def get_subscribed_emails(): view.clear_console() view.print_message("Subscribed emails: ") customers = crm.read() subscribers = list(filter(lambda x: x[-1] == '1', customers)) view.print_table(subscribers, crm.HEADERS)
def delete_customer(): view.clear_console() view.print_message("Delete customer: ") customers = crm.read() view.print_table(customers, crm.HEADERS, title='All customers:') delete_label = view.color_sentence(Fore.GREEN, "Provide customer id to remove: ") customer_index = view.get_input_number(delete_label, max_value=len(customers)) customers.pop(int(customer_index) - 1) crm.create(customers) view.print_message("Customer was removed correctly.")
def update_customer(): view.clear_console() view.print_message("Update customer: ") customers = crm.read() view.print_table(customers, crm.HEADERS, title='All customers:') update_label = view.color_sentence(Fore.GREEN, "Provide customer id to update: ") customer_index = view.get_input_number(update_label, max_value=len(customers)) - 1 customer_to_update = customers.pop(int(customer_index)) updated_customer = get_updated_customer_data(customer_to_update, crm.HEADERS) customers.insert(int(customer_index), updated_customer) crm.create(customers) view.print_message("Customer was updated correctly.")