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)
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)
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)
def process_gone_transactions(latest, account): data = read_data() new_data, gone_data = identify_new_and_gone(data, latest, account) if df_is_empty(new_data): delete_gone_from_data(gone_data) return if df_is_empty(gone_data): add_new_data(new_data) return links_to_add = [] for link_name in fields_link_ids: find_matches_gone_newsettled(new_data, gone_data, link_name, links_to_add) add_new_data(new_data) delete_gone_from_data(gone_data) for link_ids in links_to_add: link_ids_if_possible(link_ids)
def when_merge_data(self, latest_directory): self.latest = read_data_from_file(self.directory + latest_directory + 'latest.csv') merge_with_data(self.latest, 'acc') self.effective_merged = read_data()
def setUp(self): self.saved_current_data = read_data() self.effective_merged = None