|
@@ -245,19 +245,16 @@ class AdhesionAdmin(AdtSearchMixin, admin.ModelAdmin):
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
if not obj:
|
|
|
return False
|
|
|
- membership = obj.membership.current
|
|
|
one_year_ago = timezone.now() - timedelta(days=365)
|
|
|
- # si l’adhérent a un cotisation qui n’est pas arrêté depuis plus d’un an
|
|
|
- if membership and (membership.payment_method != PaymentUpdate.STOP or membership.start > one_year_ago):
|
|
|
+ membership = obj.membership.updates.filter(validated=True).first()
|
|
|
+ # si l’adhésion n’a pas été résilié il y a plus d’un an
|
|
|
+ if not membership or membership.payment_method != PaymentUpdate.STOP or membership.start > one_year_ago:
|
|
|
return False
|
|
|
# si l’adhérent est référent pour une antenne
|
|
|
- if obj.antenna_set.all():
|
|
|
+ if obj.antenna_set.exists():
|
|
|
return False
|
|
|
- # si l’adherent a un service qui a une IP alloué depuis moins d’un an
|
|
|
- if any(map(lambda s: any(map(lambda a: a.end is None or a.end > one_year_ago, s.allocations.all())), obj.services.all())):
|
|
|
- return False
|
|
|
- # si l’adhérent a un service qui a une contribution qui n’est pas arrêté depuis plus d’un an
|
|
|
- if any(map(lambda s: s.contribution.current and (s.contribution.current.payment_method != PaymentUpdate.STOP or s.contribution.current.start > one_year_ago), obj.services.all())):
|
|
|
+ # si l’adherent a un service
|
|
|
+ if obj.services.exists():
|
|
|
return False
|
|
|
return True
|
|
|
|