Commit 92a5c04e authored by Élie Bouttier's avatar Élie Bouttier

réaffectation des services inactifs impossible

parent 6c3cc3a8
......@@ -16,6 +16,7 @@ from django.core.cache import cache
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponseRedirect
from django.core.exceptions import ValidationError
from djgeojson.views import GeoJSONLayerView
from urllib.parse import urlencode
......@@ -332,6 +333,17 @@ class ServicePortInline(PortInline):
readonly_fields = ('switch', 'port', 'up',)
### Forms
class ServiceForm(ModelForm):
def clean_adhesion(self):
if self.instance.adhesion.pk != self.cleaned_data['adhesion'].pk \
and not self.instance.is_active():
raise ValidationError('Il n’est pas possible de ré-affecter à un autre adhérent un service inactif (i.e. sans allocations actives).')
return self.cleaned_data['adhesion']
### ModelAdmin
class ServiceAdmin(admin.ModelAdmin):
......@@ -346,6 +358,7 @@ class ServiceAdmin(admin.ModelAdmin):
fields = ('adhesion', 'service_type', 'label', 'notes', 'loan_equipment', 'get_contribution_link', 'is_active',)
readonly_fields = ('get_contribution_link', 'is_active',)
raw_id_fields = ('adhesion',)
form = ServiceForm
def save_model(self, request, srv, form, change):
if 'adhesion' in form.changed_data:
......
Markdown is supported
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