def is_valid_transaction_df(df): print('#is_valid_transaction') print(df) if missing_valid_amount(df): return failure_response('no valid amount') if missing_mandatory_field(df): return failure_response('missing mandatory field') return success_response()
def remove_data_on_id_if_possible(id_to_remove): transaction_to_delete = get_transaction_with_id(id_to_remove) if transaction_to_delete.shape[0] == 0: return failure_response('ID not found, nothing to delete') if set(transaction_to_delete['account'].tolist()) & set(auto_accounts): return failure_response('Impossible to remove automatic transaction') remove_data_on_id(id_to_remove) return success_response()
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()
def create_deposit(deposit_data): try: deposit_df = turn_deposit_data_into_df(deposit_data) add_new_deposit(format_deposit_df(deposit_df)) return success_response() except: return failure_response('Unknown deposit error')
def set_field_to_value_on_ids_deposit_input(ids, field_name, field_value): if field_name == 'id': return failure_response('Impossible to change id') deposit_input = read_deposit_input() change_field_on_several_ids_to_value(deposit_input, ids, field_name, field_value) save_deposit_input(deposit_input) return success_response()
def post(): json_input = request.json try: dates = json_input['dates'] cycle = json_input['cycle'] edit_calendar(dates, cycle) except: return failure_response('invalid data')
def edit_transaction(fields): if 'id' not in fields: return failure_response('invalid id') transaction_id = fields['id'] response = success_response() for field in set(fields) - {'id'}: if field == 'cycle': response = change_cycle_on_id(transaction_id, fields[field]) else: response = set_field_to_value_on_ids([transaction_id], field, fields[field]) return response
def create_deposit_references_if_possible(this_id, category): if not category: return failure_response("category cannot be empty") deposit_name = get_deposit_name_from_provision_id(this_id) status_category = status_field_not_empty('category', category) if is_successful(status_category): cat_ref_added = add_reference(deposit_name_col, category_col, deposit_name, category) if is_successful(cat_ref_added): categorize_deposit_input(this_id, category) return cat_ref_added return status_category
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()
def create_single_recurring(name, number=None): rec = get_possible_recurring() df = rec[rec.index == name].reset_index() if df.shape[0] != 1: return failure_response('Invalid name') valid_response = is_valid_transaction_df(df) print(valid_response) if is_successful(valid_response): format_recurring_transaction(df) if number: df['name'] = (str(number) + ' ' + df['name'] + 's') if number > 1 else df['name'] df['amount'] = int(number) * df['amount'] add_new_data(df) return valid_response
def create_name_references_if_possible(this_id, name, category): if not name: return failure_response("name cannot be empty") bank_name = get_bank_name_from_id(this_id) status_name = status_field_not_empty('name', name) if is_successful(status_name): name_ref_added = add_reference('bank_name', 'name', bank_name, name) if is_successful(name_ref_added): rename(this_id, name) else: return status_name status_category = status_field_not_empty('category', category) if is_successful(status_category): cat_ref_added = add_reference('name', 'category', name, category) if is_successful(cat_ref_added): categorize(this_id, category) else: return status_category return merge_status([name_ref_added, cat_ref_added])
def create_transfer_if_possible(id_one_way, account_destination): transaction_to_copy = get_transaction_with_id(id_one_way) if transaction_to_copy.shape[0] != 1: return failure_response('invalid id') return _create_transfer(transaction_to_copy, account_destination)
def status_field_not_empty(field_name, field_value): if field_value is None: return failure_response('No ' + field_name + ' Entered') return success_response()