Skip to content

Commit

Permalink
job_applications: fix is_active_company_member
Browse files Browse the repository at this point in the history
to check that the membership is still active
  • Loading branch information
xavfernandez committed Dec 20, 2024
1 parent 6d6df25 commit 8728df1
Show file tree
Hide file tree
Showing 3 changed files with 659 additions and 622 deletions.
9 changes: 8 additions & 1 deletion itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from itou.approvals.models import Approval, Suspension
from itou.approvals.notifications import PassAcceptedEmployerNotification
from itou.companies.enums import SIAE_WITH_CONVENTION_KINDS, CompanyKind, ContractType
from itou.companies.models import CompanyMembership
from itou.eligibility.enums import AuthorKind
from itou.eligibility.models import EligibilityDiagnosis, SelectedAdministrativeCriteria
from itou.job_applications.enums import (
Expand Down Expand Up @@ -134,7 +135,13 @@ class JobApplicationWorkflow(xwf_models.Workflow):

class JobApplicationQuerySet(models.QuerySet):
def is_active_company_member(self, user):
return self.filter(to_company__members=user, to_company__members__is_active=True)
return self.filter(
Exists(
CompanyMembership.objects.filter(
user=user, is_active=True, user__is_active=True, company=OuterRef("to_company")
)
)
)

def pending(self):
return self.filter(state__in=JobApplicationWorkflow.PENDING_STATES)
Expand Down
16 changes: 16 additions & 0 deletions tests/job_applications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ def test_inverted_vae_contract(self):
assert "Un contrat associé à une VAE inversée n'est possible que pour les GEIQ" in str(excinfo.value)


class TestJobApplicationQueryset:
def test_is_active_company_member(self):
job_application = JobApplicationFactory()
user = EmployerFactory()
assert JobApplication.objects.is_active_company_member(user).count() == 0

job_application.to_company.add_or_activate_member(user)
assert JobApplication.objects.is_active_company_member(user).get() == job_application

membership = job_application.to_company.memberships.filter(user=user).get()
membership.is_active = False
membership.save(update_fields=("is_active",))

assert JobApplication.objects.is_active_company_member(user).count() == 0


def test_can_be_cancelled():
assert JobApplicationFactory().can_be_cancelled is True

Expand Down
Loading

0 comments on commit 8728df1

Please sign in to comment.