Пример #1
0
def link_the_refunds():
    for link_name in fields_link_ids:
        data = read_data()
        pending = get_pending_transactions(data)
        refunds = get_refund_transactions(data)

        if df_is_not_empty(pending) & df_is_not_empty(refunds):
            add_link_ids(pending, '-', '+')
            add_link_ids(refunds, '+', '-')

            find_matches_pending_refunds(pending, refunds, link_name)
Пример #2
0
def add_new_deposit(new_dep):
    if df_is_not_empty(new_dep):
        warn('#add_deposit ------- Adding DEPOSIT: -------')
        info_df(new_dep)
        info('#add_deposit -----------------------------\n')
        deposit = concat_lines([read_deposit_input(), new_dep])
        save_deposit_input(deposit)
Пример #3
0
def add_new_data(new_data):
    if df_is_not_empty(new_data):
        warn('#add_data ------- Adding : -------')
        info_df(new_data)
        info('#add_data -----------------------------\n')
        data = concat_lines([read_data(), new_data])
        save_data(data)
Пример #4
0
def make_refund_split_transaction(transaction):
    if df_is_not_empty(transaction):
        reverse_amount(transaction)
        assign_new_column(transaction, 'type', 'FIC')
        apply_function_to_field_overrule(transaction, 'date', datetime_to_timestamp, destination='timestamp')
        create_id(transaction)
    return transaction
Пример #5
0
def find_matches_gone_newsettled(new, gone, link_name, links_to_add):
    data = read_data()
    free_new = new[new['replaces_a_pending'] == False]
    for index_gone in gone.index.tolist():
        link_value = get_loc_df(gone, index_gone, link_name)
        match = filter_df_one_value(free_new, link_name, link_value)

        if df_is_not_empty(match):
            index_new_settled = max(match.index)

            gone_transaction = gone.loc[index_gone]
            settled_transaction = new.loc[index_new_settled]
            warn('\n#merge_data ------- Identified : -------')
            info_df(
                concat_lines([
                    gone_transaction.to_frame().T,
                    settled_transaction.to_frame().T
                ]))
            info('merge_data -----------------------------\n')

            to_relink_after_gone_replaced_with_settled(data, gone_transaction,
                                                       settled_transaction,
                                                       links_to_add)
            data = read_data()
            id_to_remove = gone.loc[index_gone, 'id']
            recover_editable_fields(new, index_new_settled, gone, index_gone)

            drop_line_with_index(gone, index_gone)
            remove_data_on_id(id_to_remove)
            warn('#merge_data removing transaction' + '\n' +
                 str(filter_df_one_value(data, 'id', id_to_remove)))
            assign_value_to_loc(new, index_new_settled, 'replaces_a_pending',
                                True)
Пример #6
0
def identify_new_and_gone(data, latest_data, account):
    if df_is_not_empty(latest_data):
        add_link_ids(latest_data, '+', '-')
        condition1 = data['account'] == account
        condition2 = data['type'] != 'FIC'
        previous_data = data[both_series_are_true(condition1, condition2)]
        new_data = latest_data[latest_data['id'].isin(previous_data['id']) ==
                               False]
        previous_in_range = previous_data[
            previous_data['date'] >= min(latest_data['date'])]
        gone_data = previous_in_range[previous_in_range['id'].isin(
            latest_data['id']) == False]
        if df_is_not_empty(gone_data):
            add_link_ids(gone_data, '+', '-')
            add_column_with_value(new_data, 'replaces_a_pending', False)
            return new_data, gone_data
        return new_data, empty_data_dataframe()
    return empty_data_dataframe(), empty_data_dataframe()
Пример #7
0
def get_budgets(cycle):
    budgets = read_budgets()
    if cycle != 'all':
        budgets = budgets[budgets[cycle_col] == decode_cycle(cycle)]

    if df_is_not_empty(budgets):
        budgets = budgets.groupby(category_col).apply(sum)[[amount_euro_col, currency_col]]
        return budgets

    return empty_df(columns=[amount_euro_col, currency_col])
Пример #8
0
def delete_gone_from_data(gone):
    if df_is_not_empty(gone):
        warn('#merge_data NOT FOUND GONE TRANSACTIONS :')
        info('\n#delete_data ------- Deleting : -------')
        info_df(gone)
        info('Filtering out PT transactions')
        gone = filter_df_not_this_value(gone, 'type', 'PT')
        info('\n#delete_data ------- TO DELETE : -------')
        info_df(gone)
        info('#delete_data -----------------------------\n')
        data = filter_df_not_these_values(read_data(), 'id',
                                          get_one_field(gone, 'id'))
        save_data(data)
Пример #9
0
def find_matches_pending_refunds(pending, refunds, link_name):
    for index_refund in refunds.index.tolist()[::-1]:
        link_value = get_loc_df(refunds, index_refund, link_name)
        deposit_value = get_loc_df(refunds, index_refund, deposit_name_col)
        cycle_value = get_loc_df(refunds, index_refund, cycle_col)
        match = filter_df_one_value(pending, link_name, link_value)
        match = filter_df_one_value(match, deposit_name_col, deposit_value)
        match = filter_df_one_value(match, cycle_col, cycle_value)

        if df_is_not_empty(match):
            index_pending = max(match.index)
            id_refund = get_loc_df(refunds, index_refund, 'id')
            id_pending = get_loc_df(pending, index_pending, 'id')
            if is_successful(link_ids_if_possible(id_refund + ',' +
                                                  id_pending)):
                drop_line_with_index(pending, index_pending)