foodsoft/app/controllers/finance/bank_accounts_controller.rb
Philipp Rothmann fb2b4d8a8a chore: rubocop
chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
2023-06-09 17:35:05 +02:00

49 lines
1.5 KiB
Ruby

class Finance::BankAccountsController < Finance::BaseController
def index
@bank_accounts = BankAccount.order('name')
redirect_to finance_bank_account_transactions_url(@bank_accounts.first) if @bank_accounts.count == 1
end
def assign_unlinked_transactions
@bank_account = BankAccount.find(params[:id])
count = @bank_account.assign_unlinked_transactions
redirect_to finance_bank_account_transactions_url(@bank_account), notice: t('.notice', count: count)
rescue StandardError => e
redirect_to finance_bank_account_transactions_url(@bank_account), alert: t('errors.general_msg', msg: e.message)
end
def import
@bank_account = BankAccount.find(params[:id])
importer = @bank_account.find_connector
if importer
importer.load params[:state] && YAML.load(params[:state])
ok = importer.import params[:controls]
importer.finish if ok
flash.notice = t('.notice', count: importer.count) if ok
@auto_submit = importer.auto_submit
@controls = importer.controls
# TODO: encrypt state
@state = YAML.dump importer.dump
else
ok = true
flash.alert = t('.no_import_method')
end
needs_redirect = ok
rescue StandardError => e
flash.alert = t('errors.general_msg', msg: e.message)
needs_redirect = true
ensure
return unless needs_redirect
redirect_path = finance_bank_account_transactions_url(@bank_account)
if request.post?
@js_redirect = redirect_path
else
redirect_to redirect_path
end
end
end