diff --git a/lib/tasks/application_forms.rake b/lib/tasks/application_forms.rake index f476ce67ff..31a8ac09b6 100644 --- a/lib/tasks/application_forms.rake +++ b/lib/tasks/application_forms.rake @@ -67,4 +67,44 @@ namespace :application_forms do puts application_form.reference end end + + desc "Decline applications with less than 9 months of work experience." + task :decline_work_history_duration, + %i[staff_email] => :environment do |_task, _args| + zimbabwe = Country.find_by!(code: "ZW").regions.first + + ApplicationForm + .not_started_stage + .where.not(region: zimbabwe) + .where(needs_work_history: true) + .each do |application_form| + if WorkHistoryDuration.for_application_form( + application_form, + ).enough_for_submission? + next + end + + assessment = application_form.assessment + + assessment_section = assessment.sections.find_by!(key: "work_history") + assessment_section.selected_failure_reasons.create!( + key: FailureReasons::WORK_HISTORY_DURATION, + assessor_feedback: + "You have added at least one teaching role that started before you " \ + "were recognised as a teacher.\n\nWe do not accept teaching work " \ + "experience that was gained before you were recognised as a " \ + "teacher.\n\nThis means you have less than 9 months teaching work " \ + "history and are not eligible for QTS.\n\nYou can reapply for QTS " \ + "once you have gained more teaching work experience. If you have " \ + "this experience already, you can reapply and provide evidence of " \ + "this as part of your new application.", + ) + + application_form.reload + + DeclineQTS.call(application_form:, user:) + + puts application_form.reference + end + end end