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
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
|
|
@ -1,22 +1,22 @@
|
|||
class Finance::FinancialTransactionsController < ApplicationController
|
||||
before_action :authenticate_finance
|
||||
before_action :find_ordergroup, :except => [:new_collection, :create_collection, :index_collection]
|
||||
before_action :find_ordergroup, except: %i[new_collection create_collection index_collection]
|
||||
inherit_resources
|
||||
# belongs_to :ordergroup
|
||||
|
||||
def index
|
||||
if params['sort']
|
||||
sort = case params['sort']
|
||||
when "date" then "created_on"
|
||||
when "note" then "note"
|
||||
when "amount" then "amount"
|
||||
when "date_reverse" then "created_on DESC"
|
||||
when "note_reverse" then "note DESC"
|
||||
when "amount_reverse" then "amount DESC"
|
||||
sort = if params['sort']
|
||||
case params['sort']
|
||||
when 'date' then 'created_on'
|
||||
when 'note' then 'note'
|
||||
when 'amount' then 'amount'
|
||||
when 'date_reverse' then 'created_on DESC'
|
||||
when 'note_reverse' then 'note DESC'
|
||||
when 'amount_reverse' then 'amount DESC'
|
||||
end
|
||||
else
|
||||
sort = "created_on DESC"
|
||||
end
|
||||
else
|
||||
'created_on DESC'
|
||||
end
|
||||
|
||||
@q = FinancialTransaction.ransack(params[:q])
|
||||
@financial_transactions_all = @q.result(distinct: true).includes(:user).order(sort)
|
||||
|
|
@ -26,9 +26,11 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
@financial_transactions = @financial_transactions_all.page(params[:page]).per(@per_page)
|
||||
|
||||
respond_to do |format|
|
||||
format.js; format.html { render }
|
||||
format.js
|
||||
format.html { render }
|
||||
format.csv do
|
||||
send_data FinancialTransactionsCsv.new(@financial_transactions_all).to_csv, filename: 'transactions.csv', type: 'text/csv'
|
||||
send_data FinancialTransactionsCsv.new(@financial_transactions_all).to_csv, filename: 'transactions.csv',
|
||||
type: 'text/csv'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -38,11 +40,11 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
if @ordergroup
|
||||
@financial_transaction = @ordergroup.financial_transactions.build
|
||||
else
|
||||
@financial_transaction = FinancialTransaction.new
|
||||
end
|
||||
@financial_transaction = if @ordergroup
|
||||
@ordergroup.financial_transactions.build
|
||||
else
|
||||
FinancialTransaction.new
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
@ -53,16 +55,18 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
else
|
||||
@financial_transaction.save!
|
||||
end
|
||||
redirect_to finance_group_transactions_path(@ordergroup), notice: I18n.t('finance.financial_transactions.controller.create.notice')
|
||||
rescue ActiveRecord::RecordInvalid => error
|
||||
flash.now[:alert] = error.message
|
||||
render :action => :new
|
||||
redirect_to finance_group_transactions_path(@ordergroup),
|
||||
notice: I18n.t('finance.financial_transactions.controller.create.notice')
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash.now[:alert] = e.message
|
||||
render action: :new
|
||||
end
|
||||
|
||||
def destroy
|
||||
transaction = FinancialTransaction.find(params[:id])
|
||||
transaction.revert!(current_user)
|
||||
redirect_to finance_group_transactions_path(transaction.ordergroup), notice: t('finance.financial_transactions.controller.destroy.notice')
|
||||
redirect_to finance_group_transactions_path(transaction.ordergroup),
|
||||
notice: t('finance.financial_transactions.controller.destroy.notice')
|
||||
end
|
||||
|
||||
def new_collection
|
||||
|
|
@ -88,17 +92,17 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
|
||||
params[:financial_transactions].each do |trans|
|
||||
# ignore empty amount fields ...
|
||||
unless trans[:amount].blank?
|
||||
amount = LocalizeInput.parse(trans[:amount]).to_f
|
||||
note = params[:note]
|
||||
ordergroup = Ordergroup.find(trans[:ordergroup_id])
|
||||
if params[:set_balance]
|
||||
note += " (#{amount})"
|
||||
amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class)
|
||||
end
|
||||
ordergroup.add_financial_transaction!(amount, note, @current_user, type, financial_link)
|
||||
foodcoop_amount -= amount
|
||||
next if trans[:amount].blank?
|
||||
|
||||
amount = LocalizeInput.parse(trans[:amount]).to_f
|
||||
note = params[:note]
|
||||
ordergroup = Ordergroup.find(trans[:ordergroup_id])
|
||||
if params[:set_balance]
|
||||
note += " (#{amount})"
|
||||
amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class)
|
||||
end
|
||||
ordergroup.add_financial_transaction!(amount, note, @current_user, type, financial_link)
|
||||
foodcoop_amount -= amount
|
||||
end
|
||||
|
||||
if params[:create_foodcoop_transaction]
|
||||
|
|
@ -107,7 +111,7 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
user: @current_user,
|
||||
amount: foodcoop_amount,
|
||||
note: params[:note],
|
||||
financial_link: financial_link,
|
||||
financial_link: financial_link
|
||||
})
|
||||
ft.save!
|
||||
end
|
||||
|
|
@ -117,8 +121,8 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
|
||||
url = financial_link ? finance_link_url(financial_link.id) : finance_ordergroups_url
|
||||
redirect_to url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
|
||||
rescue => error
|
||||
flash.now[:alert] = error.message
|
||||
rescue StandardError => e
|
||||
flash.now[:alert] = e.message
|
||||
render action: :new_collection
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue