diff --git a/backend/samfundet/models/recruitment.py b/backend/samfundet/models/recruitment.py index 514fcda9d..0646e5fc4 100644 --- a/backend/samfundet/models/recruitment.py +++ b/backend/samfundet/models/recruitment.py @@ -398,7 +398,6 @@ def save(self, *args: tuple, **kwargs: dict) -> None: # noqa: C901 ) if shared_interview: self.interview = shared_interview.interview - super().save(*args, **kwargs) def get_total_interviews(self) -> int: @@ -426,6 +425,13 @@ def update_applicant_state(self) -> None: application.applicant_state = RecruitmentApplicantStates.NOT_WANTED application.save() + def clean_set_recruiter_status(self, status: RecruitmentStatusChoices) -> RecruitmentStatusChoices: + if status not in [RecruitmentStatusChoices.CALLED_AND_ACCEPTED, RecruitmentStatusChoices.CALLED_AND_REJECTED]: + return status + if timezone.now() < self.recruitment.reprioritization_deadline_for_groups: + return self.recruiter_status + return status + class RecruitmentInterviewAvailability(CustomBaseModel): """This models all possible times for interviews for the given recruitment. diff --git a/backend/samfundet/tests/test_views.py b/backend/samfundet/tests/test_views.py index fead6f652..61a610ae3 100644 --- a/backend/samfundet/tests/test_views.py +++ b/backend/samfundet/tests/test_views.py @@ -971,8 +971,15 @@ def test_update_application_recruiter_priority_gang( def test_update_application_recruiter_status_gang( - fixture_rest_client: APIClient, fixture_user: User, fixture_user2: User, fixture_recruitment_application: RecruitmentApplication + fixture_rest_client: APIClient, + fixture_recruitment: Recruitment, + fixture_user: User, + fixture_user2: User, + fixture_recruitment_application: RecruitmentApplication, ): + # Need to find a way to adjust timezone or set the times of recruitment to now + # To able to set recruitment to now due to the fields are required to be in future + ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_user2) fixture_recruitment_application.user = fixture_user2 @@ -1047,7 +1054,11 @@ def test_update_application_recruiter_priority_position( def test_update_application_recruiter_status_position( - fixture_rest_client: APIClient, fixture_user: User, fixture_user2: User, fixture_recruitment_application: RecruitmentApplication + fixture_rest_client: APIClient, + fixture_recruitment: Recruitment, + fixture_user: User, + fixture_user2: User, + fixture_recruitment_application: RecruitmentApplication, ): ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_user2) diff --git a/backend/samfundet/views.py b/backend/samfundet/views.py index 59666f8aa..de4fe95a7 100644 --- a/backend/samfundet/views.py +++ b/backend/samfundet/views.py @@ -1071,7 +1071,7 @@ def put(self, request: Request, pk: int) -> Response: if 'recruiter_priority' in update_serializer.data: application.recruiter_priority = update_serializer.data['recruiter_priority'] if 'recruiter_status' in update_serializer.data: - application.recruiter_status = update_serializer.data['recruiter_status'] + application.recruiter_status = application.clean_set_recruiter_status(update_serializer.data['recruiter_status']) application.save() applications = RecruitmentApplication.objects.filter( recruitment_position__gang=application.recruitment_position.gang, @@ -1097,7 +1097,7 @@ def put(self, request: Request, pk: int) -> Response: if 'recruiter_priority' in update_serializer.data: application.recruiter_priority = update_serializer.data['recruiter_priority'] if 'recruiter_status' in update_serializer.data: - application.recruiter_status = update_serializer.data['recruiter_status'] + application.recruiter_status = application.clean_set_recruiter_status(update_serializer.data['recruiter_status']) application.save() application.update_applicant_state() applications = RecruitmentApplication.objects.filter(