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:
Philipp Rothmann 2023-05-12 13:01:12 +02:00 committed by Philipp Rothmann
parent f6fb804bbe
commit fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions

View file

@ -5,7 +5,7 @@ class Finance::BalancingController < Finance::BaseController
def new
@order = Order.find(params[:order_id])
flash.now.alert = t('finance.balancing.new.alert') if @order.closed?
flash.now.alert = t('.alert') if @order.closed?
@comments = @order.comments
@articles = @order.order_articles.ordered_or_member.includes(:article, :article_price,
@ -13,13 +13,13 @@ class Finance::BalancingController < Finance::BaseController
sort_param = params['sort'] || 'name'
@articles = case sort_param
when 'name' then
when 'name'
@articles.order('articles.name ASC')
when 'name_reverse' then
when 'name_reverse'
@articles.order('articles.name DESC')
when 'order_number' then
when 'order_number'
@articles.order('articles.order_number ASC')
when 'order_number_reverse' then
when 'order_number_reverse'
@articles.order('articles.order_number DESC')
else
@articles
@ -31,13 +31,13 @@ class Finance::BalancingController < Finance::BaseController
def new_on_order_article_create # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
render layout: false
end
def new_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
render layout: false
end
def update_summary
@ -46,29 +46,29 @@ class Finance::BalancingController < Finance::BaseController
def edit_note
@order = Order.find(params[:id])
render :layout => false
render layout: false
end
def update_note
@order = Order.find(params[:id])
if @order.update(params[:order])
render :layout => false
render layout: false
else
render :action => :edit_note, :layout => false
render action: :edit_note, layout: false
end
end
def edit_transport
@order = Order.find(params[:id])
render :layout => false
render layout: false
end
def update_transport
@order = Order.find(params[:id])
@order.update!(params[:order])
redirect_to new_finance_order_path(order_id: @order.id)
rescue => error
redirect_to new_finance_order_path(order_id: @order.id), alert: t('errors.general_msg', msg: error.message)
rescue StandardError => e
redirect_to new_finance_order_path(order_id: @order.id), alert: t('errors.general_msg', msg: e.message)
end
# before the order will booked, a view lists all Ordergroups and its order_prices
@ -81,18 +81,18 @@ class Finance::BalancingController < Finance::BaseController
@order = Order.find(params[:id])
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
@order.close!(@current_user, @type)
redirect_to finance_order_index_url, notice: t('finance.balancing.close.notice')
rescue => error
redirect_to new_finance_order_url(order_id: @order.id), alert: t('finance.balancing.close.alert', message: error.message)
redirect_to finance_order_index_url, notice: t('.notice')
rescue StandardError => e
redirect_to new_finance_order_url(order_id: @order.id), alert: t('.alert', message: e.message)
end
# Close the order directly, without automaticly updating ordergroups account balances
def close_direct
@order = Order.find(params[:id])
@order.close_direct!(@current_user)
redirect_to finance_order_index_url, notice: t('finance.balancing.close_direct.notice')
rescue => error
redirect_to finance_order_index_url, alert: t('finance.balancing.close_direct.alert', message: error.message)
redirect_to finance_order_index_url, notice: t('.notice')
rescue StandardError => e
redirect_to finance_order_index_url, alert: t('.alert', message: e.message)
end
def close_all_direct_with_invoice
@ -103,8 +103,8 @@ class Finance::BalancingController < Finance::BaseController
count += 1
end
end
redirect_to finance_order_index_url, notice: t('finance.balancing.close_all_direct_with_invoice.notice', count: count)
rescue => error
redirect_to finance_order_index_url, alert: t('errors.general_msg', msg: error.message)
redirect_to finance_order_index_url, notice: t('.notice', count: count)
rescue StandardError => e
redirect_to finance_order_index_url, alert: t('errors.general_msg', msg: e.message)
end
end

View file

@ -8,8 +8,8 @@ class Finance::BankAccountsController < Finance::BaseController
@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 => error
redirect_to finance_bank_account_transactions_url(@bank_account), alert: t('errors.general_msg', msg: error.message)
rescue StandardError => e
redirect_to finance_bank_account_transactions_url(@bank_account), alert: t('errors.general_msg', msg: e.message)
end
def import
@ -33,8 +33,8 @@ class Finance::BankAccountsController < Finance::BaseController
end
needs_redirect = ok
rescue => error
flash.alert = t('errors.general_msg', msg: error.message)
rescue StandardError => e
flash.alert = t('errors.general_msg', msg: e.message)
needs_redirect = true
ensure
return unless needs_redirect

View file

@ -3,26 +3,30 @@ class Finance::BankTransactionsController < ApplicationController
inherit_resources
def index
if params["sort"]
sort = case params["sort"]
when "date" then "date"
when "amount" then "amount"
when "financial_link" then "financial_link_id"
when "date_reverse" then "date DESC"
when "amount_reverse" then "amount DESC"
when "financial_link_reverse" then "financial_link_id DESC"
sort = if params['sort']
case params['sort']
when 'date' then 'date'
when 'amount' then 'amount'
when 'financial_link' then 'financial_link_id'
when 'date_reverse' then 'date DESC'
when 'amount_reverse' then 'amount DESC'
when 'financial_link_reverse' then 'financial_link_id DESC'
end
else
sort = "date DESC"
end
else
'date DESC'
end
@bank_account = BankAccount.find(params[:bank_account_id])
@bank_transactions_all = @bank_account.bank_transactions.order(sort).includes(:financial_link)
@bank_transactions_all = @bank_transactions_all.where('reference LIKE ? OR text LIKE ?', "%#{params[:query]}%", "%#{params[:query]}%") unless params[:query].nil?
unless params[:query].nil?
@bank_transactions_all = @bank_transactions_all.where('reference LIKE ? OR text LIKE ?', "%#{params[:query]}%",
"%#{params[:query]}%")
end
@bank_transactions = @bank_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 BankTransactionsCsv.new(@bank_transactions_all).to_csv, filename: 'transactions.csv', type: 'text/csv'
end

View file

@ -1,5 +1,5 @@
class Finance::FinancialLinksController < Finance::BaseController
before_action :find_financial_link, except: [:create, :incomplete]
before_action :find_financial_link, except: %i[create incomplete]
def show
@items = @financial_link.bank_transactions.map do |bt|
@ -37,7 +37,7 @@ class Finance::FinancialLinksController < Finance::BaseController
def create
@financial_link = FinancialLink.first_unused_or_create
if params[:bank_transaction] then
if params[:bank_transaction]
bank_transaction = BankTransaction.find(params[:bank_transaction])
bank_transaction.update_attribute :financial_link, @financial_link
end
@ -72,14 +72,16 @@ class Finance::FinancialLinksController < Finance::BaseController
def create_financial_transaction
financial_transaction = FinancialTransaction.new(financial_transaction_params)
financial_transaction.ordergroup.add_financial_transaction! financial_transaction.amount, financial_transaction.note, current_user, financial_transaction.financial_transaction_type, @financial_link
financial_transaction.ordergroup.add_financial_transaction! financial_transaction.amount,
financial_transaction.note, current_user, financial_transaction.financial_transaction_type, @financial_link
redirect_to finance_link_url(@financial_link), notice: t('.notice')
rescue => error
redirect_to finance_link_url(@financial_link), alert: t('errors.general_msg', msg: error)
rescue StandardError => e
redirect_to finance_link_url(@financial_link), alert: t('errors.general_msg', msg: e)
end
def index_financial_transaction
@financial_transactions = FinancialTransaction.without_financial_link.includes(:financial_transaction_type, :ordergroup)
@financial_transactions = FinancialTransaction.without_financial_link.includes(:financial_transaction_type,
:ordergroup)
end
def add_financial_transaction
@ -123,7 +125,7 @@ class Finance::FinancialLinksController < Finance::BaseController
end
def find_best_fitting_ordergroup_id_for_financial_link(financial_link_id)
FinancialTransaction.joins(<<-SQL).order(created_on: :desc).pluck(:ordergroup_id).first
FinancialTransaction.joins(<<-SQL).order(created_on: :desc).pick(:ordergroup_id)
JOIN bank_transactions a ON financial_transactions.financial_link_id = a.financial_link_id
JOIN bank_transactions b ON a.iban = b.iban AND b.financial_link_id = #{financial_link_id.to_i}
SQL

View file

@ -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

View file

@ -1,15 +1,16 @@
class Finance::InvoicesController < ApplicationController
before_action :authenticate_finance_or_invoices
before_action :find_invoice, only: [:show, :edit, :update, :destroy]
before_action :ensure_can_edit, only: [:edit, :update, :destroy]
before_action :find_invoice, only: %i[show edit update destroy]
before_action :ensure_can_edit, only: %i[edit update destroy]
def index
@invoices_all = Invoice.includes(:supplier, :deliveries, :orders).order('date DESC')
@invoices = @invoices_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 InvoicesCsv.new(@invoices_all).to_csv, filename: 'invoices.csv', type: 'text/csv'
end
@ -20,11 +21,10 @@ class Finance::InvoicesController < ApplicationController
@suppliers = Supplier.includes(:invoices).where('invoices.paid_on IS NULL').references(:invoices)
end
def show
end
def show; end
def new
@invoice = Invoice.new :supplier_id => params[:supplier_id]
@invoice = Invoice.new supplier_id: params[:supplier_id]
@invoice.deliveries << Delivery.find_by_id(params[:delivery_id]) if params[:delivery_id]
@invoice.orders << Order.find_by_id(params[:order_id]) if params[:order_id]
fill_deliveries_and_orders_collection @invoice.id, @invoice.supplier_id
@ -36,12 +36,14 @@ class Finance::InvoicesController < ApplicationController
def form_on_supplier_id_change
fill_deliveries_and_orders_collection params[:invoice_id], params[:supplier_id]
render :layout => false
render layout: false
end
def fill_deliveries_and_orders_collection(invoice_id, supplier_id)
@deliveries_collection = Delivery.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id, supplier_id).order(date: :desc).limit(25)
@orders_collection = Order.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id, supplier_id).order(ends: :desc).limit(25)
@deliveries_collection = Delivery.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id,
supplier_id).order(date: :desc).limit(25)
@orders_collection = Order.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id,
supplier_id).order(ends: :desc).limit(25)
end
def create
@ -58,7 +60,7 @@ class Finance::InvoicesController < ApplicationController
end
else
fill_deliveries_and_orders_collection @invoice.id, @invoice.supplier_id
render :action => "new"
render action: 'new'
end
end
@ -81,7 +83,7 @@ class Finance::InvoicesController < ApplicationController
@invoice = Invoice.find(params[:invoice_id])
type = MIME::Types[@invoice.attachment_mime].first
filename = "invoice_#{@invoice.id}_attachment.#{type.preferred_extension}"
send_data(@invoice.attachment_data, :filename => filename, :type => type)
send_data(@invoice.attachment_data, filename: filename, type: type)
end
private
@ -92,8 +94,8 @@ class Finance::InvoicesController < ApplicationController
# Returns true if @current_user can edit the invoice..
def ensure_can_edit
unless @invoice.user_can_edit?(current_user)
deny_access
end
return if @invoice.user_can_edit?(current_user)
deny_access
end
end

View file

@ -1,11 +1,11 @@
class Finance::OrdergroupsController < Finance::BaseController
def index
m = /^(?<col>name|sum_of_class_\d+)(?<reverse>_reverse)?$/.match params["sort"]
m = /^(?<col>name|sum_of_class_\d+)(?<reverse>_reverse)?$/.match params['sort']
if m
sort = m[:col]
sort += ' DESC' if m[:reverse]
else
sort = "name"
sort = 'name'
end
@ordergroups = Ordergroup.undeleted.order(sort)