Skip to content

Commit

Permalink
Merge pull request #940 from CHSS-IT/canceled_date_fix
Browse files Browse the repository at this point in the history
Canceled date fix
  • Loading branch information
CraigJZ authored Nov 19, 2024
2 parents 9d358bf + e0b75b1 commit a7f64f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def self.import(filepath)
header = %w[section_id term department cross_list_group course_description section_number title credits level status enrollment_limit actual_enrollment cross_list_enrollment waitlist modality modality_description print_flag]
# Parse spreadsheet.
@updated_sections = 0
@uncanceled_sections = 0
(first_row..last_real_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
# Hack to avoid blanks and headers when dealing with generated csv or xslt with disclaimer rows
Expand Down Expand Up @@ -189,6 +190,14 @@ def self.import(filepath)
end
end

if section.status != 'C'
if section.status_changed? || section.canceled_at.present?
section.canceled_at = nil
@uncanceled_sections += 1
@import_report.report_item('Executing Import', 'Uncanceled Sections', "#{section.section_and_number} in #{section.term}")
end
end

# Save if changed, touch if unchanged
if section.changed? || section.enrollments.last.new_record?
section.save!
Expand All @@ -208,6 +217,7 @@ def self.import(filepath)
@new_sections = created.size
if touched.size > 0
@import_report.report_item('Executing Import', 'Updated Sections', "<a href='/sections' class='dropdown-item'>#{@updated_sections} sections were updated during the import process. #{@new_sections} sections were created.</a>")
@import_report.report_item('Executing Import', 'Uncanceled Sections', "#{@uncanceled_sections} sections where uncanceled")
else
@import_report.report_item('Executing Import', 'Updated Sections', "<a href='/sections' class='dropdown-item'>The import file was empty.</a>")
end
Expand Down
11 changes: 11 additions & 0 deletions test/models/section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ class SectionTest < ActiveSupport::TestCase
assert_not_nil @section_three.canceled_at
end

test 'import identifies uncanceled sections' do
assert_equal @section.status, 'CN'
@section.update(status: 'C', canceled_at: Time.now)
assert_equal @section.status, 'C'
assert_not_nil @section.canceled_at
Section.import(file_fixture('test_crse.csv'))
@section.reload
assert_equal @section.status, 'CN'
assert_nil @section.canceled_at
end

test 'import creates an enrollment for a section' do
assert_difference('@section.enrollments.count', + 1) do
Section.import(file_fixture('test_crse.csv'))
Expand Down

0 comments on commit a7f64f8

Please sign in to comment.