From 9e3fb05669737d18c4ec8b43b2e47acc49ef3f12 Mon Sep 17 00:00:00 2001 From: dp-daly Date: Wed, 31 Jul 2024 15:21:18 +0100 Subject: [PATCH] Add academic years to seed --- db/seeds.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/db/seeds.rb b/db/seeds.rb index 0199874ea..b355906bd 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -78,6 +78,41 @@ # Create subjects PublishTeacherTraining::Subject::Import.call +# Create academic years +year = Date.current.year +month = Date.current.month + +current_academic_year = if month < 9 + year - 1 + else + year + end + +previous_academic_year = current_academic_year - 1 +next_academic_year = current_academic_year + 1 + +[previous_academic_year, current_academic_year, next_academic_year].each do |start_year| + end_year = start_year + 1 + academic_year = AcademicYear.find_or_create_by!( + starts_on: Date.parse("1 September #{start_year}"), + ends_on: Date.parse("31 August #{end_year}"), + name: "#{start_year} to #{end_year}", + ) + next unless start_year == current_academic_year + + Claims::ClaimWindow.find_or_create_by!( + starts_on: Date.parse("2 May #{end_year}"), + ends_on: Date.parse("19 July #{end_year}"), + academic_year:, + ) + + Claims::ClaimWindow.find_or_create_by!( + starts_on: Date.parse("29 July #{end_year}"), + ends_on: Date.parse("9 August #{end_year}"), + academic_year:, + ) +end + # Create placements Placements::School.find_each do |school| # A school must have a school contact before creating placements