Skip to content

Commit

Permalink
ISSUE #448: Correction at migration of Program level and affiliation …
Browse files Browse the repository at this point in the history
…and program_levels_controller.rb
  • Loading branch information
IgorMonardez committed Dec 19, 2024
1 parent 87fce7f commit 406717d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
16 changes: 2 additions & 14 deletions app/controllers/program_levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ProgramLevelsController < ApplicationController
authorize_resource

active_scaffold :program_level do |config|
config.create.columns = [:level, :start_date, :end_date]
config.update.columns = [:level, :start_date, :end_date]
Expand All @@ -11,22 +12,9 @@ class ProgramLevelsController < ApplicationController
config.actions.swap :search, :field_search
config.columns.add :active
config.field_search.columns = [:active]
config.columns[:active].form_ui = :select

config.actions.exclude :deleted_records
end

protected
def do_update

old_record = ProgramLevel.find_by_id(params[:id])

super

if old_record.level.to_s != @record.level
new_record = old_record.dup
new_record.end_date = @record.start_date
new_record.save
end
flash[:info] = "Atualizado com sucesso! Atualize a página para ter todos os conceitos CAPES."
end
end
14 changes: 10 additions & 4 deletions db/migrate/20240524135850_create_affiliation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ def up
)
professor = professor.paper_trail.previous_version
while professor.present?
if professor.institution_id != institution_id
# A data final é a data inicial da instituição anterior
end_date = start_date
# A data inicial é quando o professor recebeu algum
start_date = professor.updated_at
if professor.institution_id != institution_id && (start_date - end_date).abs > 1.month
# Atualiza a data caso a mudança de instituição seja maior que 1 mes
institutions << { institution_id:, start_date:, end_date: }
end_date = start_date - 1.month
start_date = professor.updated_at - 1.month
institution_id = professor.institution_id
affiliation = Affiliation.create(
professor: professor,
Expand All @@ -32,7 +35,10 @@ def up
end_date: end_date
)
else
# Atualiza data de início para data da primeira mudança em que instituição foi definida com esse valor
affiliation.update(start_date: start_date)
end
# Se for a primeira versão do professor diminui a data de start da affiliation em um mês
if professor.paper_trail.previous_version.nil?
start_date = professor.updated_at - 1.month
affiliation.update(start_date: start_date)
end
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20240527174758_create_program_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def up
level = pl.value
program_level = ProgramLevel.create(
level: pl.value,
start_date: pl.updated_at - 1.month,
start_date: pl.updated_at,
)
pl = pl.paper_trail.previous_version
while pl.present?
if pl.value != level
end_date = program_level.start_date - 1.month
start_date = pl.updated_at - 1.month
end_date = program_level.start_date
start_date = pl.updated_at
level = pl.value
program_level = ProgramLevel.create(
level: level,
Expand All @@ -34,7 +34,7 @@ def up
CustomVariable.where(variable: "program_level").destroy_all
end
def down
ProgramLevel.all.each do |pl|
ProgramLevel.all&.where(end_date: nil)&.each do |pl|
CustomVariable.create(
variable: "program_level",
value: pl.level,
Expand Down

0 comments on commit 406717d

Please sign in to comment.