Commit 40b52a05 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

contribution_long_stopped

parent 41c15e64
......@@ -15,9 +15,6 @@ class ActiveAdhesionManager(models.Manager):
def get_queryset(self):
qs = super().get_queryset()
one_year_ago = timezone.now() - timedelta(days=366)
long_stopped_services = Service.objects.filter(
adhesion=models.OuterRef("pk"), long_stopped=False
)
return qs.annotate(
last_echeance=models.Subquery(
Echeance.objects.filter(adhesion=models.OuterRef("pk")).values("date")[
......@@ -40,7 +37,11 @@ class ActiveAdhesionManager(models.Manager):
default=True,
output_field=models.BooleanField(null=True),
),
services_long_stopped=~models.Exists(long_stopped_services),
services_long_stopped=~models.Exists(
Service.objects.filter(adhesion=models.OuterRef("pk")).filter(
long_stopped=False
)
),
long_stopped=models.Case(
models.When(services_long_stopped=False, then=False),
models.When(
......@@ -59,9 +60,8 @@ class User(AuthUser):
return {}
@property
def adhesions(
self,
): # user and corporations (for which the user is a member) adhesions
def adhesions(self):
"""user and corporations (for which the user is a member) adhesions"""
return self.profile.adhesions
@property
......@@ -120,9 +120,12 @@ class Corporation(models.Model):
return self.social_reason
# Terminologie : une « adhésion » désgine une instance de ce modèle
# tandis qu’un·e « adhérent·e » désigne un·e user ou une corporation.
class Adhesion(models.Model):
"""
Terminologie : une « adhésion » désgine une instance de ce modèle
tandis qu’un·e « adhérent·e » désigne un·e user ou une corporation.
"""
limit = models.Q(app_label="auth", model="user") | models.Q(
app_label="adhesions", model="corporation"
)
......
......@@ -88,9 +88,14 @@ class ActiveServiceManager(models.Manager):
& (Q(end__isnull=True) | Q(end__gte=one_year_ago))
)
),
contribution_long_stopped=models.Exists(
RecurringPayment.objects.filter(
service=models.OuterRef("pk"), long_stopped=True
)
),
long_stopped=models.Case(
models.When(contribution__isnull=True, then=False),
models.When(contribution__long_stopped=False, then=False),
models.When(contribution_long_stopped=False, then=False),
models.When(allocations_long_stopped=False, then=False),
default=True,
output_field=models.BooleanField(),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment