Commit 1d6ebed3 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

fix import loop

parent 8a63e837
......@@ -7,6 +7,7 @@ from django.contrib.humanize.templatetags.humanize import naturalday
from datetime import timedelta
from services.models import Service
from banking.models import RecurringPayment, PaymentUpdate, Echeance
......@@ -14,6 +15,9 @@ 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")[
......@@ -36,7 +40,7 @@ class ActiveAdhesionManager(models.Manager):
default=True,
output_field=models.BooleanField(null=True),
),
services_long_stopped=~models.Exists(services__long_stopped=False),
services_long_stopped=~models.Exists(long_stopped_services),
long_stopped=models.Case(
models.When(services_long_stopped=False, then=False),
models.When(
......
from django.apps import apps
from django.db import models
from django.db.models import Q
from django.core.validators import MaxValueValidator
......@@ -15,7 +16,6 @@ from base64 import urlsafe_b64encode
from datetime import timedelta
from djadhere.utils import get_active_filter, is_overlapping
from adhesions.models import Adhesion
from banking.models import RecurringPayment
......@@ -243,7 +243,7 @@ class Service(models.Model):
"""
adhesion = models.ForeignKey(
Adhesion,
"adhesions.Adhesion",
verbose_name="Adhérent·e",
related_name="services",
on_delete=models.CASCADE,
......@@ -321,6 +321,7 @@ class Route(models.Model):
return allocations.values_list("resource", flat=True)
def get_adh(self):
Adhesion = apps.get_model("adhesions", "Adhesion")
allocations = self.allocations.filter(get_active_filter())
return Adhesion.objects.filter(
pk__in=allocations.values_list("service__adhesion", flat=True)
......
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