Skip to content

Commit

Permalink
Fix autocorrectable offenses using Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMajeri committed Nov 24, 2024
1 parent b30ec36 commit a1b286e
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 73 deletions.
57 changes: 32 additions & 25 deletions app/controllers/commitments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ def new
@commitment.registration_date = Time.zone.today
@commitment.created_by_user = current_user

if params[:source_expenditure_id].present?
@source_expenditure = Expenditure.find(params[:source_expenditure_id])

@commitment.financing_sources << @source_expenditure.financing_source
@commitment.expenditure_article = @source_expenditure.expenditure_article
@commitment.procurement_type = @source_expenditure.procurement_type
@commitment.project_details = @source_expenditure.details
@commitment.partner = @source_expenditure.beneficiary
@commitment.value = @source_expenditure.value
@commitment.remarks = @source_expenditure.remarks
end
return unless params[:source_expenditure_id].present?

@source_expenditure = Expenditure.find(params[:source_expenditure_id])

@commitment.financing_sources << @source_expenditure.financing_source
@commitment.expenditure_article = @source_expenditure.expenditure_article
@commitment.procurement_type = @source_expenditure.procurement_type
@commitment.project_details = @source_expenditure.details
@commitment.partner = @source_expenditure.beneficiary
@commitment.value = @source_expenditure.value
@commitment.remarks = @source_expenditure.remarks
end

def edit
Expand Down Expand Up @@ -79,13 +79,14 @@ def create
user: current_user,
action: :insert,
target_table: :commitments,
target_object_id: "#{@commitment.registration_number}/#{@commitment.year}",
target_object_id: "#{@commitment.registration_number}/#{@commitment.year}"
)
end
end

if successfully_saved
flash[:notice] = "A fost salvat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}"
flash[:notice] =
"A fost salvat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}"
redirect_to commitments_path
else
flash[:alert] = 'Nu s-a putut salva noul angajament. Verificați erorile și încercați din nou.'
Expand All @@ -105,10 +106,11 @@ def update
user: current_user,
action: :update,
target_table: :commitments,
target_object_id: "#{@commitment.registration_number}/#{@commitment.year}",
target_object_id: "#{@commitment.registration_number}/#{@commitment.year}"
)

flash[:notice] = "A fost modificat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}"
flash[:notice] =
"A fost modificat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}"
redirect_to commitments_path
else
flash[:alert] = 'Nu s-au putut salva modificările la angajament. Verificați erorile și încercați din nou.'
Expand Down Expand Up @@ -215,13 +217,13 @@ def apply_filters

if params[:start_date].present?
start_date = Date.strptime(params[:start_date], '%d.%m.%Y')
@commitments = @commitments.where('registration_date >= ?', start_date)
@commitments = @commitments.where(registration_date: start_date..)
@any_filters_applied = true
end

if params[:end_date].present?
end_date = Date.strptime(params[:end_date], '%d.%m.%Y')
@commitments = @commitments.where('registration_date <= ?', end_date)
@commitments = @commitments.where(registration_date: ..end_date)
@any_filters_applied = true
end

Expand Down Expand Up @@ -283,7 +285,10 @@ def parse_commitment(row_index, row)

financing_sources_column = row[4]&.strip&.downcase

raise ImportError.new(row_index, 'lipsește reprezentantul UB / sursa de finanțare') if financing_sources_column.blank?
if financing_sources_column.blank?
raise ImportError.new(row_index,
'lipsește reprezentantul UB / sursa de finanțare')
end

financing_sources = []
project_details = ''
Expand Down Expand Up @@ -315,9 +320,9 @@ def parse_commitment(row_index, row)
'pr cu tva', 'pr nationale', 'pr internationale', 'proiecte internationale',
'proiecte in valuta', 'pr in valuta',
/^ctr\./,
/^pfe /, /^pfe\//, /^fcs /, /^fcs\//,
/^fss\//, /^fss /, /^proiecte fss/,
/^cpi\//,
/^pfe /, %r{^pfe/}, /^fcs /, %r{^fcs/},
%r{^fss/}, /^fss /, /^proiecte fss/,
%r{^cpi/},
/^lifewatch/, /^timss/,
/^proiect caipe/, /^pr growing/, /^pr employer/, /^pr ev potential/, /^pr siec/,
/^proiect addendum/,
Expand Down Expand Up @@ -377,7 +382,7 @@ def parse_commitment(row_index, row)
when /^trace/
project_details = financing_sources_column.strip
financing_sources << FinancingSource.find_by(name: 'Erasmus')
when /^erasmus\//
when %r{^erasmus/}
project_details = financing_sources_column.delete_prefix('erasmus').delete_prefix('/')
.strip
financing_sources << FinancingSource.find_by(name: 'Erasmus')
Expand Down Expand Up @@ -498,7 +503,7 @@ def parse_commitment(row_index, row)
financing_sources << FinancingSource.find_by(name: 'Serviciul Spații de Învățământ')
when 'achizitii'
financing_sources << FinancingSource.find_by(name: 'Serviciul Achiziții Publice')
when /^achizitii\//
when %r{^achizitii/}
project_details = financing_sources_column.strip
financing_sources << FinancingSource.find_by(name: 'Serviciul Achiziții Publice')
when 'ru'
Expand Down Expand Up @@ -563,7 +568,8 @@ def parse_commitment(row_index, row)
# Remove entries which weren't found
financing_sources.filter!(&:present?)
if financing_sources.empty?
raise ImportError.new(row_index, "nu a putut fi găsită o sursă de finanțare denumită '#{financing_sources_column}'")
raise ImportError.new(row_index,
"nu a putut fi găsită o sursă de finanțare denumită '#{financing_sources_column}'")
end

commitment.financing_sources = financing_sources
Expand All @@ -586,7 +592,8 @@ def parse_commitment(row_index, row)

expenditure_article = ExpenditureArticle.find_by(code: expenditure_article_code)
if expenditure_article.nil?
raise ImportError.new(row_index, "nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'")
raise ImportError.new(row_index,
"nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'")
end

commitment.expenditure_article = expenditure_article
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/concerns/filtrable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def apply_string_field_filter(collection, field_name, param_key = nil)

def apply_value_range_filter(collection)
if params[:min_value].present?
collection = collection.where('value >= ?', params[:min_value])
collection = collection.where(value: params[:min_value]..)
@any_filters_applied = true
end

if params[:max_value].present?
collection = collection.where('value <= ?', params[:max_value])
collection = collection.where(value: ..params[:max_value])
@any_filters_applied = true
end

Expand Down Expand Up @@ -76,7 +76,8 @@ def apply_exclude_cash_receipts_filter(collection)
collection = collection.where.not(expenditure_article: receipts_expenditure_article)
@any_filters_applied = true
else
flash[:alert] = 'Nu s-a putut aplica filtrul deoarece nu este definit articolul de cheltuială cu codul 12, "Încasări"'
flash[:alert] =
'Nu s-a putut aplica filtrul deoarece nu este definit articolul de cheltuială cu codul 12, "Încasări"'
end
end
end
Expand Down
15 changes: 8 additions & 7 deletions app/controllers/expenditure_articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create
user: current_user,
action: :insert,
target_table: :expenditure_articles,
target_object_id: @expenditure_article.id,
target_object_id: @expenditure_article.id
)
end
end
Expand Down Expand Up @@ -59,7 +59,7 @@ def update
user: current_user,
action: :update,
target_table: :expenditure_articles,
target_object_id: @expenditure_article.id,
target_object_id: @expenditure_article.id
)
end
end
Expand All @@ -68,7 +68,8 @@ def update
flash[:notice] = "A fost actualizat cu succes articolul de cheltuială cu codul #{@expenditure_article.code}"
redirect_to expenditure_articles_path
else
flash[:alert] = 'Nu s-au putut salva modificările la articolul de cheltuială. Verificați erorile și încercați din nou.'
flash[:alert] =
'Nu s-au putut salva modificările la articolul de cheltuială. Verificați erorile și încercați din nou.'
render :edit, status: :unprocessable_entity
end
end
Expand All @@ -87,15 +88,16 @@ def destroy
user: current_user,
action: :delete,
target_table: :expenditure_articles,
target_object_id: @expenditure_article.id,
target_object_id: @expenditure_article.id
)
end
end

if successfully_deleted
flash[:notice] = "A fost șters cu succes articolul de cheltuială cu codul #{@expenditure_article.code}"
else
flash[:alert] = "Nu s-a putut șterge articolul de cheltuială: #{@expenditure_article.errors.full_messages.join(', ')}."
flash[:alert] =
"Nu s-a putut șterge articolul de cheltuială: #{@expenditure_article.errors.full_messages.join(', ')}."
end

redirect_to expenditure_articles_path
Expand Down Expand Up @@ -137,10 +139,9 @@ def import_upload

flash[:notice] = "S-au importat/actualizat cu succes #{total_count} articole de cheltuială!"
redirect_to expenditure_articles_path

rescue ImportError => e
flash.now[:alert] = e.to_s
return render :import
render :import
end

private
Expand Down
25 changes: 12 additions & 13 deletions app/controllers/expenditures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ def create
user: current_user,
action: :insert,
target_table: :expenditures,
target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}",
target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}"
)
end
end

if successfully_saved
flash[:notice] = t('expenditures.create.success_message',
flash[:notice] = t('.success_message',
registration_number: @expenditure.registration_number,
year: @expenditure.year)
redirect_to expenditures_path
else
flash[:alert] = t 'expenditures.create.error_message'
flash[:alert] = t '.error_message'
render :new, status: :unprocessable_entity
end
end
Expand All @@ -91,15 +91,15 @@ def update
user: current_user,
action: :update,
target_table: :expenditures,
target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}",
target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}"
)

flash[:notice] = t('expenditures.update.success_message',
flash[:notice] = t('.success_message',
registration_number: @expenditure.registration_number,
year: @expenditure.year)
redirect_to expenditures_path
else
flash[:alert] = t 'expenditures.update.error_message'
flash[:alert] = t '.error_message'
render :edit, status: :unprocessable_entity
end
end
Expand Down Expand Up @@ -218,13 +218,13 @@ def apply_filters

if params[:start_date].present?
start_date = Date.strptime(params[:start_date], '%d.%m.%Y')
@expenditures = @expenditures.where('registration_date >= ?', start_date)
@expenditures = @expenditures.where(registration_date: start_date..)
@any_filters_applied = true
end

if params[:end_date].present?
end_date = Date.strptime(params[:end_date], '%d.%m.%Y')
@expenditures = @expenditures.where('registration_date <= ?', end_date)
@expenditures = @expenditures.where(registration_date: ..end_date)
@any_filters_applied = true
end

Expand Down Expand Up @@ -276,7 +276,6 @@ def apply_filters

@expenditures = apply_created_by_user_ids_filter @expenditures
@expenditures = apply_updated_by_user_ids_filter @expenditures

end

# noinspection SpellCheckingInspection
Expand Down Expand Up @@ -439,7 +438,8 @@ def parse_expenditure(row_index, row)
end

if financing_source.nil?
raise ImportError.new(row_index, "nu a putut fi găsită o sursă de finanțare cunoscută asociată cu denumirea '#{financing_source_name}'")
raise ImportError.new(row_index,
"nu a putut fi găsită o sursă de finanțare cunoscută asociată cu denumirea '#{financing_source_name}'")
end

expenditure_article_code = row[3].to_s.strip
Expand All @@ -453,7 +453,8 @@ def parse_expenditure(row_index, row)

expenditure_article = ExpenditureArticle.find_by(code: expenditure_article_code)
if expenditure_article.nil?
raise ImportError.new(row_index, "nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'")
raise ImportError.new(row_index,
"nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'")
end

expenditure.expenditure_article = expenditure_article
Expand Down Expand Up @@ -705,8 +706,6 @@ def parse_expenditure(row_index, row)
PaymentType.find_by(name: 'Avans numerar')
when 'avans virament'
PaymentType.find_by(name: 'Avans virament')
else
nil
end

if payment_type.nil?
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/financing_sources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create
user: current_user,
action: :insert,
target_table: :financing_sources,
target_object_id: @financing_source.id,
target_object_id: @financing_source.id
)
end
end
Expand Down Expand Up @@ -59,7 +59,7 @@ def update
user: current_user,
action: :update,
target_table: :financing_sources,
target_object_id: @financing_source.id,
target_object_id: @financing_source.id
)
end
end
Expand Down Expand Up @@ -87,7 +87,7 @@ def destroy
user: current_user,
action: :delete,
target_table: :financing_sources,
target_object_id: @financing_source.id,
target_object_id: @financing_source.id
)
end
end
Expand Down Expand Up @@ -132,7 +132,6 @@ def import_upload

flash[:notice] = "S-au importat/actualizat cu succes #{total_count} surse de finanțare!"
redirect_to financing_sources_path

rescue ImportError => e
flash.now[:alert] = e.to_s
render :import
Expand Down
11 changes: 4 additions & 7 deletions app/controllers/payment_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def update
user: current_user,
action: :update,
target_table: :payment_types,
target_object_id: @payment_type.id,
target_object_id: @payment_type.id
)
end
end
Expand Down Expand Up @@ -87,7 +87,7 @@ def destroy
user: current_user,
action: :delete,
target_table: :payment_types,
target_object_id: @payment_type.id,
target_object_id: @payment_type.id
)
end
end
Expand Down Expand Up @@ -123,20 +123,17 @@ def import_upload

payment_type = PaymentType.find_or_initialize_by(name:)

unless payment_type.save
raise ImportError.new(row_index, payment_type.errors.full_messages.join(', '))
end
raise ImportError.new(row_index, payment_type.errors.full_messages.join(', ')) unless payment_type.save

total_count += 1
end
end

flash[:notice] = "S-au importat/actualizat cu succes #{total_count} tipuri de plăți!"
redirect_to payment_types_path

rescue ImportError => e
flash.now[:alert] = e.to_s
return render :import
render :import
end

private
Expand Down
Loading

0 comments on commit a1b286e

Please sign in to comment.