diff --git a/itou/users/models.py b/itou/users/models.py index f2f646b991..c74f897982 100644 --- a/itou/users/models.py +++ b/itou/users/models.py @@ -472,7 +472,7 @@ def latest_common_approval(self): self.latest_approval and self.latest_approval.is_in_waiting_period and self.latest_pe_approval - and self.latest_pe_approval.is_valid + and self.latest_pe_approval.is_valid() ): return self.latest_pe_approval diff --git a/tests/users/test_models.py b/tests/users/test_models.py index 92a4794162..215624bdb2 100644 --- a/tests/users/test_models.py +++ b/tests/users/test_models.py @@ -1122,6 +1122,21 @@ def test_latest_common_approval_when_only_pe_approval(self): pe_approval = PoleEmploiApprovalFactory(nir=user.jobseeker_profile.nir) assert user.latest_common_approval == pe_approval + def test_latest_common_approval_with_expired_pe_approval(self): + user = JobSeekerFactory() + today = timezone.localdate() + PoleEmploiApprovalFactory( + nir=user.jobseeker_profile.nir, + start_at=today - datetime.timedelta(days=30), + end_at=today - datetime.timedelta(days=1), + ) + approval = ApprovalFactory( + user=user, + start_at=today - datetime.timedelta(days=10), + end_at=today - datetime.timedelta(days=7), + ) + assert user.latest_common_approval == approval + def test_latest_common_approval_is_approval_if_valid(self): user = JobSeekerFactory() approval = ApprovalFactory(user=user)