Ejemplo n.º 1
0
def input_recap(cycle):
    overview = dict()
    data_this_cycle = filter_df_on_cycle(read_data(), cycle)
    provisions_this_cycle = filter_df_on_cycle(read_deposit_input(), cycle)
    recap_by_category = recap_by_cat(cycle, False)
    if cycle_is_finished(cycle):
        overview['Input goal'] = - round(sum(recap_by_category['amount']), 2)
        overview['(actual) Over'] = overview['Input goal'] - sum(get_budgets(cycle)[amount_euro_col])
    else:
        overview['Budgets'] = round(sum(recap_by_category['budget']), 2)
        overview['Over (so far)'] = round(sum(recap_by_category['over']), 2)
        overview['Input goal'] = overview['Budgets'] + overview['Over (so far)']

    data_this_cycle_input = filter_df_one_value(data_this_cycle, 'category', 'Input')
    provisions_this_cycle_input = filter_df_one_value(provisions_this_cycle, 'category', 'Input')
    overview['Done'] = total_euro_amount(data_this_cycle_input) - total_euro_amount(provisions_this_cycle_input)
    remaining = round(overview['Input goal'] - overview['Done'], 2)
    if remaining > 0:
        overview['Remaining TO DO'] = remaining
    elif remaining < 0:
        overview['Margin'] = - remaining

    overview = pd.Series(overview).rename('amount', inplace=True).to_frame()
    add_column_with_value(overview, currency_col, default_currency)
    return overview
Ejemplo n.º 2
0
def remove_already_present_id(df, account, limit=None):
    data = read_data()
    data_account = filter_df_one_value(data, account_col, account)
    if limit:
        data_account = data_account.head(limit)
    present_ids = data_account[id_col]
    return df[not_series(df[id_col].isin(present_ids))]
Ejemplo n.º 3
0
def _link_ids(ids):
    data = read_data()
    ids_link = ids[1:] + [ids[0]]
    for transaction_id, transaction_link in zip(ids, ids_link):
        change_field_on_single_id_to_value(data, transaction_id, 'link',
                                           transaction_link)
        change_field_on_single_id_to_value(data, transaction_id, "category",
                                           "Link")
    save_data(data)
Ejemplo n.º 4
0
def parse_ids(transaction_ids):
    if not transaction_ids:
        return 'no transaction', empty_data_dataframe()
    try:
        transaction_ids = list(transaction_ids.replace(' ', '').split(','))
    except ValueError:
        return 'invalid ID', []
    data = read_data()
    ids = list(data['id'])
    if set(transaction_ids) & set(ids) != set(transaction_ids):
        return 'transaction not found', []
    return '', transaction_ids
Ejemplo n.º 5
0
def _unlink_ids(ids):
    data = read_data()
    fields = ['link', 'category']
    force_code = "unlink_ok"
    for this_id in ids:
        all_ids = all_transactions_linked_to_this(data, this_id)
        for field in fields:
            change_field_on_several_ids_to_value(data,
                                                 all_ids,
                                                 field,
                                                 default_value(field),
                                                 force_code=force_code)
    save_data(data)
Ejemplo n.º 6
0
def split_transaction_if_possible(the_input):
    data = read_data()
    transaction = filter_df_on_id(data, the_input['id'])

    if transaction.shape[0] != 1:
        return failure_response('Invalid id')

    if not amounts_valid_split(transaction, the_input['amount1'], the_input['amount2']):
        return failure_response('Invalid amounts')

    if not all_split_fields_present(the_input):
        return failure_response('Missing fields')

    _split_transaction(the_input, transaction)
    return success_response()
Ejemplo n.º 7
0
def link_ids_if_possible(ids):
    error_message, ids = parse_ids(ids)

    if error_message:
        return error_message

    if len(ids) < 2:
        return failure_response('not enough transactions')

    data = read_data()
    data_ids = filter_df_several_values(data, 'id', ids)

    if how_many_rows(data_ids) != len(ids):
        return failure_response('at least one transaction missing')

    if round(result_function_applied_to_field(data_ids, amount_euro_col, sum),
             2) != 0:
        return failure_response('transactions do not cancel each other out')

    if present_links_is_not_empty(data_ids):
        return failure_response('one or more transaction already linked')

    _link_ids(ids)
    return success_response()
Ejemplo n.º 8
0
def get_bank_name_from_id(id):
    transaction = filter_df_on_id(read_data(), id)
    return get_first_value_from_series(
        get_one_field(transaction, bank_name_col))
Ejemplo n.º 9
0
def get_data_from_cycle(cycle):
    return filter_df_on_cycle(read_data(), cycle)
Ejemplo n.º 10
0
def get_data_this_account(account):
    return filter_df_one_value(read_data(), account_col, account)
Ejemplo n.º 11
0
def get_deposit_output():
    data = read_data()
    is_not_deposit = column_is_null(data, deposit_name_col)
    return filter_df_on_bools(data, is_not_deposit, keep=False)
Ejemplo n.º 12
0
def get_transaction_with_id(id_to_find):
    data = read_data()
    return data[data['id'] == id_to_find]
Ejemplo n.º 13
0
def filtered_data_not_this_value(field_name, field_value):
    return filter_df_not_this_value(read_data(), field_name, field_value)
Ejemplo n.º 14
0
def get_field_data(field_name):
    data = read_data()
    return data[field_name]
Ejemplo n.º 15
0
def change_cycle_on_id(transaction_id, cycle_value):
    ids = all_transactions_linked_to_this(read_data(), transaction_id)
    return set_field_to_value_on_ids(ids, 'cycle', cycle_value)