-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relax validation on ChangeSchedule service for certain participants #4838
Conversation
81ddb5a
to
5c61e21
Compare
Review app deployed to https://cpd-ecf-review-4838-web.test.teacherservices.cloud |
5c61e21
to
6859d40
Compare
6859d40
to
c17ec0d
Compare
c17ec0d
to
28db978
Compare
28db978
to
eb7bb41
Compare
eb7bb41
to
95fae5f
Compare
95fae5f
to
7ab766a
Compare
5f1a650
to
f0ca8df
Compare
def eligible_to_change_cohort_back_to_their_payments_frozen_original?(to_cohort_start_year:) | ||
to_cohort = Cohort.find_by_start_year(to_cohort_start_year) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def eligible_to_change_cohort_back_to_their_payments_frozen_original?(to_cohort_start_year:) | |
to_cohort = Cohort.find_by_start_year(to_cohort_start_year) | |
def eligible_to_change_cohort_back_to_their_payments_frozen_original?(to_cohort:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have already the cohort instance everytime we need to call this method.
Better we pass it and save one query to the db?
@@ -83,7 +92,7 @@ def self.archivable(for_cohort_start_year:, restrict_to_participant_ids: []) | |||
query = left_joins(:participant_declarations, schedule: :cohort) | |||
# Exclude participants that have any induction records that are not FIP. | |||
.where.not(id: not_fip_induction_records.select(:participant_profile_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we excluding participants not doing FIP even if they don't have billable declarations?
Maybe I don't know all requirements to archive participants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be excluding participants that once (any induction record) were associated to a non-FIP programme <> participants doing non-FIP right now (latest induction record).
Is that exactly what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't archive 2021 participants doing non-FIP programmes and with no billable declarations, they might need to be transferred to 2024.
This means the requirements for the service Induction::AmendParticipantCohort
change and we have to relax its validations to cope with these participants. Same for the ChangeSchedule
service...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requirements for the archive logic are at the bottom of Nathan's word doc, he's also included this explanation for those undeclared participants that will not be archived:
This means that there will be some undeclared participants who are not archived. A tiny number of these participants may require FIP/CIP training in the 2024 cohort (estimate 10s not 100s). It may be preferable for these participants to be transferred manually by DfE admin users if flagged by providers/helpdesk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if he wants to transfer them manually when flagged by providers/helpdesk, I am happy to leave the code as it is now.
.where(induction_completion_date: nil) | ||
.where("induction_start_date IS NULL OR induction_start_date < ?", latest_induction_start_date) | ||
.where("induction_start_date IS NULL OR induction_start_date < make_date(cohorts.start_year, 9, 1)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do the induction start date of the participant matter to archive them or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a requirement from Nathan, I'm not sure of the reasoning behind it but I'll follow up with him to check:
I think if they have an induction start date of 1/9/2021 or later, we should exclude them and not archive them. We should only archive those where there is no induction start date or it is earlier then 1/9/2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's the reasoning:
Archiving is primarily intended for participants who were registered in error. The two typical cases of this are a) where the ECT wasn't actually an ECT but was instead starting their initial teacher training and b) the ECT had already started induction before the current funding and framework kicked in.
Where an ECT did actually start induction on or after 1 Sep 2021, the training needs are trumped by the school funding needs. The record will have been used to inform school payments, so we should not archive any such records
def self.archivable(for_cohort_start_year:, restrict_to_participant_ids: []) | ||
super(for_cohort_start_year:, restrict_to_participant_ids:) | ||
def self.archivable(restrict_to_participant_ids: []) | ||
super(restrict_to_participant_ids:) | ||
.where(mentor_completion_date: nil) | ||
.where.not(id: InductionRecord.where.not(mentor_profile_id: nil).select(:mentor_profile_id).distinct) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to exclude mentors that once were assigned to an ECT no matter if they currently have any assignment or not.
Is this what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so, here's the full spec:
- 2021 cohort (according to their schedule -> cohort)
- Profile has no declarations where declaration state is one of eligible/payable/paid/awaiting_clawback/clawed_back
- Participant has only FIP induction records
- Mentor funding end date is NULL
- No mentees in induction records
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That 5th condition (No mentees in induction records) is not in Nathan's doc. (At least I can't find it).
In any case, can it mean the mentor is not CURRENTLY assigned to any mentee?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it looks like that requirement hasn't made it into the Word doc for some reason, but this was the ask from Nathan:
Could we add a criterion that the mentor has no links to any ECT in any of their induction period records?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so in that case, it is clear that he wants no mentor-mentee at any time.
app/services/change_schedule.rb
Outdated
return false unless attempt_to_change_cohort_leaving_billable_declarations | ||
return true if participant_profile.eligible_to_change_cohort_and_continue_training?(in_cohort_start_year: cohort.start_year) | ||
|
||
participant_profile.eligible_to_change_cohort_back_to_their_payments_frozen_original?(to_cohort_start_year: cohort.start_year) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
participant_profile.eligible_to_change_cohort_back_to_their_payments_frozen_original?(to_cohort_start_year: cohort.start_year) | |
participant_profile.eligible_to_change_cohort_back_to_their_payments_frozen_original?(to_cohort: cohort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...if we decide to make the change suggested above to the signature of this method
app/services/change_schedule.rb
Outdated
@@ -9,6 +9,7 @@ class ChangeSchedule | |||
attribute :course_identifier | |||
attribute :schedule_identifier | |||
attribute :cohort, :integer | |||
attribute :attempt_to_change_cohort_leaving_billable_declarations, :boolean, default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this security attribute?
Nothing will change until we set a cohort as payments-frozen in the database, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this because the ChangeSchedule
service is exposed via the lead provider API and we don't necessarily want them to be able to use it to perform this kind of cohort change yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine but if we don't set 2021 as payments-frozen yet, even if they try that cohort change the code we have written won't allow it (even if we remove attempt_to_change_cohort_leaving_billable_declarations
)
In any case, fine by me if you want to keep it for extra security reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I understand that it won't let it happen until the payments frozen is switched on, but we want this as an extra safety net as it looks like we may not want to allow providers to use the service for this purpose even when the cohort is frozen (but we want the option to trigger it via other means, so that's where the flag will come in)
We want to allow ECTs and mentors to change schedule/cohort even if they have billable declarations under certain scenarios. The participants eligible are identified by `eligible_to_change_cohort_and_continue_training`. By default the service will not allow eligible participants to transfer; it needs to be called explicitly with `attempt_to_transfer_leaving_billable_declarations` set to `true`. This is to prevent lead providers performing these changes for now. Participants that change cohort using this mechanism should be able to change back to their original cohort providing no billable declarations were created against the new cohort.
Tweaks the logic to change cohort and continue training to aign with the schools team. This means instead of checking for +/- 3 years from their current cohort, we will instead let them transfer only ot the active registration cohort and only back to a cohort that is payments frozen and for which they have billable declarations.
ba07b97
to
dbdd98d
Compare
app/services/change_schedule.rb
Outdated
changing_cohort = new_schedule.cohort != participant_profile.schedule.cohort | ||
|
||
if changing_cohort && can_change_cohort_leaving_billable_declarations? | ||
participant_profile.toggle!(:cohort_changed_after_payments_frozen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toggle!
skips validation checks, is this intentional?
Also was wondering if we could somehow have this logic into a different method to update_school_cohort_and_schedule!
to make the intention clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, good catch I'll change this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @ethax-ross for this, really cleanly implemented! I left a few minor comments, and we discussed in person possibly moving shared validations to validators but after this is merged.
- Pass in current cohort to `eligible_to_change_cohort_back_to_their_payments_frozen_original?` - Remove unused method `cohort_start_years_delta` - Select current cohort from `relevant_induction_record`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ethax-ross 💯 this took a lot of 🧠 to get through but very cleanly done
Context
We want to allow ECTs and mentors to change schedule/cohort even if they have billable declarations under certain scenarios.
The participants eligible are identified by
eligible_to_change_cohort_and_continue_training
.Participants that change cohort using this mechanism should be able to change back to their original cohort providing no billable declarations were created against the new cohort.
Changes proposed in this pull request
By default the service will not allow eligible participants to transfer; it needs to be called explicitly with
attempt_to_transfer_leaving_billable_declarations
set totrue
. This is to prevent lead providers performing these changes for now.Guidance to review
A participant will be able to transfer if:
attempt_to_transfer_leaving_billable_declarations
istrue
eligible_to_change_cohort_and_continue_training?
On transferring, the
cohort_changed_after_payments_frozen
will betrue
.A participant will be able to transfer back if:
attempt_to_transfer_leaving_billable_declarations
istrue
cohort_changed_after_payments_frozen
is true on the profilepayments_frozen
On transferring back, the
cohort_changed_after_payments_frozen
will befalse
.