Add import route for bank_transactions

This commit is contained in:
Patrick Gansterer 2018-10-11 23:26:12 +02:00
parent 0bb0536903
commit 903086ab97
5 changed files with 27 additions and 0 deletions

View file

@ -5,4 +5,18 @@ class Finance::BankAccountsController < Finance::BaseController
redirect_to finance_bank_account_transactions_url(@bank_accounts.first) if @bank_accounts.count == 1
end
def import
@bank_account = BankAccount.find(params[:id])
import_method = @bank_account.find_import_method
if import_method
count = import_method.call(@bank_account)
redirect_to finance_bank_account_transactions_url(@bank_account), notice: t('finance.bank_accounts.controller.import.notice', count: count)
else
# @todo add import for csv files as fallback
redirect_to finance_bank_account_transactions_url(@bank_account), alert: t('finance.bank_accounts.controller.import.no_import_method')
end
rescue => error
redirect_to finance_bank_account_transactions_url(@bank_account), alert: t('errors.general_msg', msg: error.message)
end
end

View file

@ -9,4 +9,7 @@ class BankAccount < ActiveRecord::Base
validates_format_of :iban, :with => /\A[A-Z]{2}[0-9]{2}[0-9A-Z]{,30}\z/
validates_numericality_of :balance, :message => I18n.t('bank_account.model.invalid_balance')
# @return [Function] Method wich can be called to import transaction from a bank or nil if unsupported
def find_import_method
end
end

View file

@ -1,5 +1,8 @@
- title t('.title', name: @bank_account.name, balance: number_to_currency(@bank_account.balance))
- content_for :actionbar do
= link_to t('.import_transaction'), import_finance_bank_account_path(@bank_account), class: 'btn btn-primary'
.well.well-small
= form_tag finance_bank_account_transactions_path, :method => :get, :remote => true,
'data-submit-onchange' => true, class: 'form-search' do