From b46c72eaff1b6c3c91976d54bea5fd51138e80d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Wed, 11 Sep 2024 11:00:44 +0200 Subject: [PATCH] Add archived_at constraint to the PRIOR_TO_HIRE state --- .../migrations/0009_jobapplication_archived_at.py | 10 +++++++--- itou/job_applications/models.py | 11 ++++++++--- tests/job_applications/tests.py | 11 ++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/itou/job_applications/migrations/0009_jobapplication_archived_at.py b/itou/job_applications/migrations/0009_jobapplication_archived_at.py index 34d7a151a31..dba7d1f2905 100644 --- a/itou/job_applications/migrations/0009_jobapplication_archived_at.py +++ b/itou/job_applications/migrations/0009_jobapplication_archived_at.py @@ -29,9 +29,13 @@ class Migration(migrations.Migration): migrations.AddConstraint( model_name="jobapplication", constraint=models.CheckConstraint( - check=models.Q(("archived_at__isnull", False), ("state", "accepted"), _negated=True), - name="archived_not_accepted", - violation_error_message="Impossible d’archiver une candidature acceptée.", + check=models.Q( + ("archived_at__isnull", False), ("state__in", ["accepted", "prior_to_hire"]), _negated=True + ), + name="archived_status", + violation_error_message=( + "Impossible d’archiver une candidature acceptée ou en action préalable à l’embauche." + ), ), ), migrations.AddConstraint( diff --git a/itou/job_applications/models.py b/itou/job_applications/models.py index 85846fdff4f..ab5133addbb 100644 --- a/itou/job_applications/models.py +++ b/itou/job_applications/models.py @@ -780,9 +780,14 @@ class Meta: ), ), models.CheckConstraint( - name="archived_not_accepted", - violation_error_message="Impossible d’archiver une candidature acceptée.", - check=~models.Q(state=JobApplicationState.ACCEPTED, archived_at__isnull=False), + name="archived_status", + violation_error_message=( + "Impossible d’archiver une candidature acceptée ou en action préalable à l’embauche." + ), + check=~models.Q( + state__in=[JobApplicationState.ACCEPTED, JobApplicationState.PRIOR_TO_HIRE], + archived_at__isnull=False, + ), ), models.CheckConstraint( name="archived_by__no_archived_at", diff --git a/tests/job_applications/tests.py b/tests/job_applications/tests.py index 1416c2b0b77..7b5bca5cfdf 100644 --- a/tests/job_applications/tests.py +++ b/tests/job_applications/tests.py @@ -1699,7 +1699,16 @@ def test_job_application_transitions(transition, from_state): pytest.param(transition, from_state, id=f"transition={transition.name} from_state={from_state}") for transition in JobApplicationWorkflow.transitions for from_state in transition.source - if JobApplicationState.ACCEPTED not in [from_state.name, transition.target.name] + if not ( + # Leads to a state that cannot be archived. + { + # Employment relationship between employer and job seeker, it is active. + JobApplicationState.ACCEPTED, + # Employer waits for a prior action before to establish an employment relationship. + JobApplicationState.PRIOR_TO_HIRE, + } + & {from_state.name, transition.target.name} + ) ], ) def test_job_application_transition_unarchives(transition, from_state):