Add import route for bank_transactions
This commit is contained in:
parent
0bb0536903
commit
903086ab97
5 changed files with 27 additions and 0 deletions
|
@ -5,4 +5,18 @@ class Finance::BankAccountsController < Finance::BaseController
|
||||||
redirect_to finance_bank_account_transactions_url(@bank_accounts.first) if @bank_accounts.count == 1
|
redirect_to finance_bank_account_transactions_url(@bank_accounts.first) if @bank_accounts.count == 1
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -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_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')
|
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
|
end
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
- title t('.title', name: @bank_account.name, balance: number_to_currency(@bank_account.balance))
|
- 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
|
.well.well-small
|
||||||
= form_tag finance_bank_account_transactions_path, :method => :get, :remote => true,
|
= form_tag finance_bank_account_transactions_path, :method => :get, :remote => true,
|
||||||
'data-submit-onchange' => true, class: 'form-search' do
|
'data-submit-onchange' => true, class: 'form-search' do
|
||||||
|
|
|
@ -905,6 +905,9 @@ en:
|
||||||
with_extra_charge: 'with extra charge:'
|
with_extra_charge: 'with extra charge:'
|
||||||
without_extra_charge: 'without extra charge:'
|
without_extra_charge: 'without extra charge:'
|
||||||
bank_accounts:
|
bank_accounts:
|
||||||
|
controller:
|
||||||
|
import:
|
||||||
|
notice: '%{count} new transactions have been imported'
|
||||||
index:
|
index:
|
||||||
account_statement: Account statement
|
account_statement: Account statement
|
||||||
title: Bank Accounts
|
title: Bank Accounts
|
||||||
|
|
|
@ -192,6 +192,10 @@ Foodsoft::Application.routes.draw do
|
||||||
post 'transactions/create_collection' => 'financial_transactions#create_collection', as: 'create_transaction_collection'
|
post 'transactions/create_collection' => 'financial_transactions#create_collection', as: 'create_transaction_collection'
|
||||||
|
|
||||||
resources :bank_accounts, only: [:index] do
|
resources :bank_accounts, only: [:index] do
|
||||||
|
member do
|
||||||
|
get :import
|
||||||
|
end
|
||||||
|
|
||||||
resources :bank_transactions, as: :transactions
|
resources :bank_transactions, as: :transactions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue