Ejemplo n.º 1
0
def edit_kind(ats: Account) -> None:
    """Prompts user for a new value for Account name
    """
    print("\nEditing Kind\n" + ("=" * 40))
    while True:
        a = bc.select_account(ats)
        if a == bc.breakout_account:
            break
        while True:
            print("\nInput New Kind\n" + ("=" * 40))
            try:
                for k, v in bc.kind_to_str.items():
                    print("{:>3}.".format(k + 1), v)
                choice_str = input(
                    "Select new name by number (Current kind: " +
                    bc.kind_to_str[a.get_kind()] + "): ")
                choice = int(choice_str) - 1
                valid.kind(choice)
                if bc.binary_question(
                        "Confirm new kind is " + bc.kind_to_str[choice] +
                        " ([y]es [n]o): ", "y", "n"):
                    a.set_kind(choice)
                if not bc.binary_question("Enter a new kind ([y]es or [n]o): ",
                                          "y", "n"):
                    break
            except Exception as e:
                print("    An error has occurred: " + str(e))
        if not bc.binary_question(
                "Edit another Account's kind ([y]es or [n]o): ", "y", "n"):
            break
Ejemplo n.º 2
0
def edit_goal(ats: Account) -> None: 
    """Mutates the goal of the selected Account and timeframe. 
    Provides user interface for mutating this information
    """
    print("\nEditing Goal\n" + ("="*40))
    while True: 
        a = bc.select_account(ats)
        if a == bc.breakout_account: 
            break
        while True: 
            print()
            y = bc.trans_timeframe(a.get_budgets())
            print()
            m = bc.months_to_int[bc.trans_timeframe([bc.months(i) for i in a.get_budgets(y)] + [-1])[:3]]
            while True: 
                print("\nInput New Goal\n" + ("="*40))
                try:
                    choice_str = input("Enter new goal (Current goal: {:.2f}): ".format(a.get_goal(y,m)/100))
                    choice = int(choice_str) * 100
                    valid.amount(choice) 
                    if bc.binary_question("Confirm new goal is {:.2f}".format(choice/100) + " ([y]es [n]o): ", "y", "n"): 
                        a.set_goal(y, m, choice)
                        break
                except Exception as e: 
                    print("    An error has occurred: " + str(e))
            if not bc.binary_question("Enter goals for other months ([y]es or [n]o): ", "y", "n"):
                break
        if not bc.binary_question("Edit a goal for another Account ([y]es or [n]o): ", "y", "n"):
            break
Ejemplo n.º 3
0
def menu(ts, i, ats) -> None:
    """Revises Transaction object based on user input 
    """
    attribs = ("yrr", "mth", "day", "dsc", "dac", "cac", "crr", "flw", "amt",
               "prc", "del", "esc")
    editing = True
    while editing:
        print(_menu + "\n\nSelected Transaction:\n" + header())
        if len(ts) == 0:
            print("    No Transactions to edit")
            break
        try:
            # Placing this in try statement prevents exception from being raised
            # when Transaction is deleted
            try:
                print(view(ts[i]))
            except:
                print("{:^100}".format(
                    "Transaction No Longer Available: It Was Deleted"))
                break
            choice = input("Your choice: ").rstrip()
            assert choice in attribs, "{} not an option.".format(choice)
            if choice == "esc":
                break
            _new_input(ts, i, as_attrib[choice], ats)
            editing = bc.binary_question("Continue editing ([y]es or [n]o): ",
                                         "y", 'n')
        except Exception as e:
            print("    An error occured: transedit.main: {}".format(e))
Ejemplo n.º 4
0
def main(ts: ["Transaction"]) -> None:
    """Requests user prompt to display information about Transactions
    """
    ts.sort(key=lambda x: (x.get_year(), x.get_month(), x.get_day()))
    viewing = True 
    while viewing: 
        print(menu)
        try: 
            choice = input("Your choice: ").rstrip()
            if choice == "yrr": 
                _by_year(ts) 
            elif choice == "mth": 
                _by_month(ts) 
            elif choice == "ymo": 
                _by_pair(ts) 
            elif choice == "cst":
                _by_custom(ts) 
            elif choice == "esc": 
                break 
            else: 
                print("Choice {} not an option. Try again.".format(choice))
        except Exception as e: 
            print("    An error occurred: " + str(e))
            break
        viewing = bc.binary_question("View more transactions? ([y]es or [n]o): ", "y", "n")
Ejemplo n.º 5
0
def main(ts: ["Transaction"]) -> None:
    """Requests user prompt to display information about Transactions
    """
    ts.sort(key=lambda x: (x.get_year(), x.get_month(), x.get_day()))
    viewing = True
    while viewing:
        print(menu)
        try:
            choice = input("Your choice: ").rstrip()
            if choice == "yrr":
                _by_year(ts)
            elif choice == "mth":
                _by_month(ts)
            elif choice == "ymo":
                _by_pair(ts)
            elif choice == "cst":
                _by_custom(ts)
            elif choice == "esc":
                break
            else:
                print("Choice {} not an option. Try again.".format(choice))
        except Exception as e:
            print("    An error occurred: " + str(e))
            break
        viewing = bc.binary_question(
            "View more transactions? ([y]es or [n]o): ", "y", "n")
Ejemplo n.º 6
0
def menu(ts, i, ats) -> None:
    """Revises Transaction object based on user input 
    """ 
    attribs = ("yrr", "mth", "day", "dsc", "dac", "cac", "crr", "flw", "amt",
               "prc", "del", "esc")
    editing = True 
    while editing:
        print(_menu+"\n\nSelected Transaction:\n" + header()) 
        if len(ts) == 0:
            print("    No Transactions to edit")
            break
        try:
            # Placing this in try statement prevents exception from being raised
            # when Transaction is deleted
            try: 
                print(view(ts[i])) 
            except: 
                print("{:^100}".format("Transaction No Longer Available: It Was Deleted"))
                break 
            choice = input("Your choice: ").rstrip()
            assert choice in attribs, "{} not an option.".format(choice)
            if choice == "esc":
                break
            _new_input(ts, i, as_attrib[choice], ats)
            editing = bc.binary_question("Continue editing ([y]es or [n]o): ", "y", 'n')
        except Exception as e: 
            print("    An error occured: transedit.main: {}".format(e))
Ejemplo n.º 7
0
def edit_name(ats: Account) -> None:
    """Prompts user for a new value for Account name
    """
    print("\nEditing Name\n" + ("="*40))
    while True: 
        a = bc.select_account(ats)
        if a == bc.breakout_account: 
            break
        while True: 
            print("\nInput New Name\n" + ("="*40))
            choice = input("New name (Current name: " + a.get_name() + "): ")
            if bc.binary_question("Confirm new name is " + choice + " ([y]es [n]o): ", "y", "n"): 
                a.set_name(choice)
            if not bc.binary_question("Enter a new name ([y]es or [n]o): ", "y", "n"):
                break
        if not bc.binary_question("Edit another Account's name ([y]es or [n]o): ", "y", "n"):
            break
Ejemplo n.º 8
0
def main(ts: [Transaction], ats: [Account]) -> None:
    """Revises Transaction from a Transaction collection, based on 
    user input 
    """
    editing = True 
    while editing: 
        t = _select_trans(ts)
        if isinstance(t, Transaction): 
            menu(ts, ts.index(t), ats)
        editing = bc.binary_question("Edit another transaction ([y]es or [n]o): ", "y", "n")
Ejemplo n.º 9
0
def main(ts: [Transaction], ats: [Account]) -> None:
    """Revises Transaction from a Transaction collection, based on 
    user input 
    """
    editing = True
    while editing:
        t = _select_trans(ts)
        if isinstance(t, Transaction):
            menu(ts, ts.index(t), ats)
        editing = bc.binary_question(
            "Edit another transaction ([y]es or [n]o): ", "y", "n")
Ejemplo n.º 10
0
def edit_name(ats: Account) -> None:
    """Prompts user for a new value for Account name
    """
    print("\nEditing Name\n" + ("=" * 40))
    while True:
        a = bc.select_account(ats)
        if a == bc.breakout_account:
            break
        while True:
            print("\nInput New Name\n" + ("=" * 40))
            choice = input("New name (Current name: " + a.get_name() + "): ")
            if bc.binary_question(
                    "Confirm new name is " + choice + " ([y]es [n]o): ", "y",
                    "n"):
                a.set_name(choice)
            if not bc.binary_question("Enter a new name ([y]es or [n]o): ",
                                      "y", "n"):
                break
        if not bc.binary_question(
                "Edit another Account's name ([y]es or [n]o): ", "y", "n"):
            break
Ejemplo n.º 11
0
def edit_goal(ats: Account) -> None:
    """Mutates the goal of the selected Account and timeframe. 
    Provides user interface for mutating this information
    """
    print("\nEditing Goal\n" + ("=" * 40))
    while True:
        a = bc.select_account(ats)
        if a == bc.breakout_account:
            break
        while True:
            print()
            y = bc.trans_timeframe(a.get_budgets())
            print()
            m = bc.months_to_int[bc.trans_timeframe(
                [bc.months(i) for i in a.get_budgets(y)] + [-1])[:3]]
            while True:
                print("\nInput New Goal\n" + ("=" * 40))
                try:
                    choice_str = input(
                        "Enter new goal (Current goal: {:.2f}): ".format(
                            a.get_goal(y, m) / 100))
                    choice = int(choice_str) * 100
                    valid.amount(choice)
                    if bc.binary_question(
                            "Confirm new goal is {:.2f}".format(choice / 100) +
                            " ([y]es [n]o): ", "y", "n"):
                        a.set_goal(y, m, choice)
                        break
                except Exception as e:
                    print("    An error has occurred: " + str(e))
            if not bc.binary_question(
                    "Enter goals for other months ([y]es or [n]o): ", "y",
                    "n"):
                break
        if not bc.binary_question(
                "Edit a goal for another Account ([y]es or [n]o): ", "y", "n"):
            break
Ejemplo n.º 12
0
def edit_kind(ats: Account) -> None:
    """Prompts user for a new value for Account name
    """
    print("\nEditing Kind\n" + ("="*40))
    while True: 
        a = bc.select_account(ats)
        if a == bc.breakout_account:
            break
        while True: 
            print("\nInput New Kind\n" + ("="*40))
            try :
                for k,v in bc.kind_to_str.items(): 
                    print("{:>3}.".format(k + 1), v)
                choice_str = input("Select new name by number (Current kind: " + bc.kind_to_str[a.get_kind()] + "): ")
                choice = int(choice_str) - 1
                valid.kind(choice) 
                if bc.binary_question("Confirm new kind is " + bc.kind_to_str[choice] + " ([y]es [n]o): ", "y", "n"): 
                    a.set_kind(choice)
                if not bc.binary_question("Enter a new kind ([y]es or [n]o): ", "y", "n"):
                    break
            except Exception as e: 
                print("    An error has occurred: " + str(e))
        if not bc.binary_question("Edit another Account's kind ([y]es or [n]o): ", "y", "n"):
            break
Ejemplo n.º 13
0
def _enter_block():
    """Loop to enter transactions under a specific month and year
    """
    ts = list()
    print("Entering year and month\n" + ("="*40))
    y = _prompt_year()
    if y == -1: 
        return ts 
    
    m = _prompt_month()
    if m == -1:
        return ts
    
    entering = True 
    while entering:
        try:  
            ts.append(_enter(y,m))
        except Exception as e: 
            print("    An error has occurred: " + str(e)) 
        else: 
            entering = bc.binary_question("Enter another question ([y]es or [n]o): ", "y", "n")
    return ts 
Ejemplo n.º 14
0
def _new_input(ts: [Transaction], trans_index: int, attrib: str,
               ats: [Account]) -> None:
    """Mutates a transaction based on user input
    """
    trans_to_edit = ts[trans_index]
    while True:
        try:
            if attrib == "day":
                choice = input("Enter new day (previous: {}): ".format(
                    trans_to_edit.get_day() + 1))
                trans_to_edit.set_day(int(eval(choice) - 1))
                break
            elif attrib == "month":
                choice = input("Enter new month (previous: {}): ".format(
                    trans_to_edit.get_month() + 1))
                trans_to_edit.set_month(int(eval(choice) - 1))
                break
            elif attrib == "year":
                choice = input("Enter new year (previous: {}): ".format(
                    trans_to_edit.get_year() + 1))
                trans_to_edit.set_year(int(eval(choice) - 1))
                break
            elif attrib == "description":
                choice = input("Enter new description (previous: {}): ".format(
                    trans_to_edit.get_description()))
                trans_to_edit.set_description(choice)
                break
            elif attrib == "dr_account":
                choice = input("Enter new account (previous: {}): ".format(
                    trans_to_edit.get_dr_account()))
                trans_to_edit.set_dr_account(choice)
                break
            elif attrib == "cr_account":
                choice = input("Enter new account (previous: {}): ".format(
                    trans_to_edit.get_cr_account()))
                trans_to_edit.set_cr_account(choice)
                break
            elif attrib == "description":
                choice = input("Enter new description (previous: {}): ".format(
                    trans_to_edit.get_currency()))
                trans_to_edit.set_currency(choice)
                break
            elif attrib == "amount":
                choice = input("Enter new amount (previous: {:.2f}): ".format(
                    round(trans_to_edit.get_amount() / 100, 2)))
                trans_to_edit.set_amount(eval(choice) * 100)
                break
            elif attrib in ("delete"):
                if bc.binary_question(
                        "Are you sure you want to delete this transaction ([y]es or [n]o): ",
                        "y", "n"):
                    for a in ats:
                        if ts[trans_index] in a:
                            a.remove(ts[trans_index])
                    ts.remove(ts[trans_index])
                    print("Transaction Successfully Deleted")
                    break
                else:
                    break
        except Exception as e:
            print("    An error has occurred: " + str(e))
        else:
            print("Transaction Successfully Updated")
Ejemplo n.º 15
0
def _opt_edit(t: Transaction) -> Transaction:
    """Prompts user to edit a Transaction
    """
    if bc.binary_question("Edit transaction ([y]es or [n]o): ", "y", "n"): 
        trans_edit.menu(t)         
    return t
Ejemplo n.º 16
0
def _new_input(ts: [Transaction], trans_index: int, attrib: str, ats: [Account]) -> None:
    """Mutates a transaction based on user input
    """
    trans_to_edit = ts[trans_index]
    while True: 
        try: 
            if attrib == "day":
                choice = input("Enter new day (previous: {}): ".format(
                    trans_to_edit.get_day() + 1))
                trans_to_edit.set_day(int(eval(choice) - 1))
                break
            elif attrib == "month":
                choice = input("Enter new month (previous: {}): ".format(
                    trans_to_edit.get_month() + 1))
                trans_to_edit.set_month(int(eval(choice) - 1))
                break
            elif attrib == "year":
                choice = input("Enter new year (previous: {}): ".format(
                    trans_to_edit.get_year() + 1)) 
                trans_to_edit.set_year(int(eval(choice) - 1))
                break
            elif attrib == "description":
                choice = input("Enter new description (previous: {}): ".format(
                    trans_to_edit.get_description())) 
                trans_to_edit.set_description(choice)
                break
            elif attrib == "dr_account":
                choice = input("Enter new account (previous: {}): ".format(
                    trans_to_edit.get_dr_account())) 
                trans_to_edit.set_dr_account(choice)
                break
            elif attrib == "cr_account":
                choice = input("Enter new account (previous: {}): ".format(
                    trans_to_edit.get_cr_account())) 
                trans_to_edit.set_cr_account(choice)
                break
            elif attrib == "description":
                choice = input("Enter new description (previous: {}): ".format(
                    trans_to_edit.get_currency())) 
                trans_to_edit.set_currency(choice)
                break
            elif attrib == "amount": 
                choice = input("Enter new amount (previous: {:.2f}): ".format(
                    round(trans_to_edit.get_amount()/100, 2) ))
                trans_to_edit.set_amount(eval(choice)*100)
                break
            elif attrib in ("delete"):
                if bc.binary_question(
                    "Are you sure you want to delete this transaction ([y]es or [n]o): ", 
                    "y", "n"):
                    for a in ats: 
                        if ts[trans_index] in a: 
                            a.remove(ts[trans_index])
                    ts.remove(ts[trans_index])
                    print("Transaction Successfully Deleted")
                    break
                else:
                    break
        except Exception as e: 
            print("    An error has occurred: " + str(e))
        else: 
            print("Transaction Successfully Updated")