diff --git a/app/models/lead_provider.rb b/app/models/lead_provider.rb index 851598b61f..f987ecd012 100644 --- a/app/models/lead_provider.rb +++ b/app/models/lead_provider.rb @@ -5,7 +5,6 @@ class LeadProvider < ApplicationRecord "Church of England" => "79cb41ca-cb6d-405c-b52c-b6f7c752388d", "LLSE" => "230e67c0-071a-4a48-9673-9d043d456281", "National Institute of Teaching" => "3ec607f2-7a3a-421f-9f1a-9aca8a634aeb", - "School-Led Network" => "bc5e4e37-1d64-4149-a06b-ad10d3c55fd0", "Teach First" => "a02ae582-f939-462f-90bc-cebf20fa8473", "UCL Institute of Education" => "ef687b3d-c1c0-4566-a295-16d6fa5d0fa7", }.freeze @@ -24,6 +23,7 @@ class LeadProvider < ApplicationRecord validates :ecf_id, uniqueness: { case_sensitive: false }, allow_nil: true scope :alphabetical, -> { order(name: :asc) } + scope :active, -> { where(ecf_id: ALL_ACTIVE_PROVIDERS.values) } def self.for(course:, cohort: Cohort.current) course_cohort = CourseCohort.find_by(course:, cohort:) diff --git a/db/migrate/20221130142333_add_hint_to_lead_providers.rb b/db/migrate/20221130142333_add_hint_to_lead_providers.rb index 855b334d58..6ea68ba0ab 100644 --- a/db/migrate/20221130142333_add_hint_to_lead_providers.rb +++ b/db/migrate/20221130142333_add_hint_to_lead_providers.rb @@ -2,7 +2,7 @@ class AddHintToLeadProviders < ActiveRecord::Migration[6.1] def up add_column :lead_providers, :hint, :string - school_led_network_lead_provider = LeadProvider.find_by(ecf_id: LeadProvider::ALL_ACTIVE_PROVIDERS["School-Led Network"]) + school_led_network_lead_provider = LeadProvider.find_by(ecf_id: "bc5e4e37-1d64-4149-a06b-ad10d3c55fd0") school_led_network_lead_provider&.update!( hint: "You can only register with this provider if you already started your NPQ with them in October 2022.", diff --git a/db/seeds/base/add_api_tokens.rb b/db/seeds/base/add_api_tokens.rb index 9b44b0fa72..9d7ecbeee4 100644 --- a/db/seeds/base/add_api_tokens.rb +++ b/db/seeds/base/add_api_tokens.rb @@ -2,7 +2,6 @@ "Ambition Institute" => "ambition-token", "Best Practice Network" => "best-practice-token", "Church of England" => "coe-token", - "School-Led Network" => "school-led-token", "UCL Institute of Education" => "ucl-token", "Teach First" => "teach-first-token", "National Institute of Teaching" => "niot-token", diff --git a/lib/tasks/one_off/update_statement_move_declarations_3678.rake b/lib/tasks/one_off/update_statement_move_declarations_3678.rake new file mode 100644 index 0000000000..1fd8335b55 --- /dev/null +++ b/lib/tasks/one_off/update_statement_move_declarations_3678.rake @@ -0,0 +1,59 @@ +namespace :one_off do + desc "One off task for ticket NPQ-3678 to update statement and move declarations" + task :update_statement_move_declarations, %i[dry_run] => :versioned_environment do |_task, args| + Rails.logger = Logger.new($stdout) unless Rails.env.test? + dry_run = args[:dry_run] != "false" + + Rails.logger.info "DRY RUN: will roll back at end" if dry_run + + ActiveRecord::Base.transaction do + lead_providers = LeadProvider.active + + lead_providers.each do |lead_provider| + statement = Statement.find_by( + month: 9, + year: 2026, + cohort: Cohort.find_by!(identifier: "2025a"), + lead_provider:, + ) + statement.update!(output_fee: true) + + Rails.logger.info "Set output_fee: true on #{statement.month}/#{statement.year} statement, cohort: #{statement.cohort.identifier}, lead provider: #{statement.lead_provider.name}" + end + + leadership_course_identifiers = %w[ + npq-early-years-leadership + npq-executive-leadership + npq-headship + npq-senco + npq-senior-leadership + ] + + Rails.logger.info "Move retained-2 leadership declarations from July 2026 to August 2026 for 2025a cohort" + + migrator = OneOff::MigrateDeclarationsBetweenStatements + .new( + from_year: 2026, + from_month: 7, + to_year: 2026, + to_month: 8, + cohort: Cohort.find_by!(identifier: "2025a"), + override_date_checks: true, + restrict_to_course_identifiers: leadership_course_identifiers, + restrict_to_declaration_types: "retained-2", + from_statement_updates: { output_fee: false }, + to_statement_updates: { output_fee: true }, + ) + + unless migrator.migrate(dry_run:) + Rails.logger.info "Validation failure:" + Rails.logger.info migrator.errors.full_messages.to_yaml + end + + if dry_run + Rails.logger.info "DRY RUN: rolling back transaction" + raise ActiveRecord::Rollback + end + end + end +end diff --git a/spec/lib/tasks/one_off/sandbox_test_data_2026_spec.rb b/spec/lib/tasks/one_off/sandbox_test_data_2026_spec.rb index 4fee1d0466..1eb35d1a0f 100644 --- a/spec/lib/tasks/one_off/sandbox_test_data_2026_spec.rb +++ b/spec/lib/tasks/one_off/sandbox_test_data_2026_spec.rb @@ -40,8 +40,8 @@ expect { run_task } .to change(Cohort, :count).from(3).to(4) .and change(Schedule, :count).from(1).to(12) - .and change(Application, :count).from(0).to(78) - .and change(User, :count).from(0).to(78) + .and change(Application, :count).from(0).to(69) + .and change(User, :count).from(0).to(69) end end end diff --git a/spec/models/lead_provider_spec.rb b/spec/models/lead_provider_spec.rb index ebc5e0d127..16ff128a67 100644 --- a/spec/models/lead_provider_spec.rb +++ b/spec/models/lead_provider_spec.rb @@ -16,6 +16,30 @@ it { is_expected.to validate_uniqueness_of(:ecf_id).case_insensitive.with_message("ECF ID must be unique").allow_nil } end + describe "scopes" do + describe ".alphabetical" do + subject { described_class.alphabetical } + + it "returns lead providers in name alphabetical order" do + expect(subject).to eq LeadProvider.order(name: :asc) + end + end + + describe ".active" do + subject { described_class.active } + + before do + create(:lead_provider, name: "Education Development Trust", ecf_id: "21e61f53-9b34-4384-a8f5-d8224dbf946d") + create(:lead_provider, name: "School-Led Network", ecf_id: "bc5e4e37-1d64-4149-a06b-ad10d3c55fd0") + create(:lead_provider, name: "Teacher Development Trust", ecf_id: "30fd937e-b93c-4f81-8fff-3c27544193f1") + end + + it "returns lead providers in ALL_ACTIVE_PROVIDERS" do + expect(subject).to eq LeadProvider.where(ecf_id: LeadProvider::ALL_ACTIVE_PROVIDERS.values) + end + end + end + describe "#for" do subject { described_class.for(course:, cohort:).map(&:name) }