|
@@ -7,12 +7,16 @@ from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
|
|
|
from django.http import HttpResponseRedirect
|
|
|
from django.utils.html import format_html, mark_safe
|
|
|
from django.core.urlresolvers import reverse
|
|
|
+from django.utils import timezone
|
|
|
|
|
|
from .forms import UserCreationForm
|
|
|
from .models import User, Corporation, Adhesion
|
|
|
from accounts.models import Profile
|
|
|
from services.models import Service
|
|
|
from djadhere.utils import ActiveFilter
|
|
|
+from banking.models import PaymentUpdate
|
|
|
+
|
|
|
+from datetime import timedelta
|
|
|
|
|
|
|
|
|
### Inlines
|
|
@@ -239,7 +243,23 @@ class AdhesionAdmin(AdtSearchMixin, admin.ModelAdmin):
|
|
|
return False
|
|
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
- return False
|
|
|
+ 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):
|
|
|
+ return False
|
|
|
+ # si l’adhérent est référent pour une antenne
|
|
|
+ if obj.antenna_set.all():
|
|
|
+ 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())):
|
|
|
+ return False
|
|
|
+ return True
|
|
|
|
|
|
|
|
|
admin.site.unregister(AuthUser)
|