Add inline edit functionality to destinataer detail view - Added toggle between view and edit modes while maintaining elegant card design - Implemented AJAX form submission for seamless saving - Added JavaScript functionality for edit/save/cancel operations - Enhanced user experience with keyboard shortcuts and notifications
This commit is contained in:
@@ -1200,6 +1200,73 @@ def destinataer_update(request, pk):
|
||||
destinataer = get_object_or_404(Destinataer, pk=pk)
|
||||
if request.method == "POST":
|
||||
form = DestinataerForm(request.POST, instance=destinataer)
|
||||
|
||||
# Handle AJAX requests
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
if form.is_valid():
|
||||
try:
|
||||
destinataer = form.save()
|
||||
|
||||
# Auto-create a Destinatärunterstützung if conditions are met
|
||||
if (
|
||||
destinataer.aktiv
|
||||
and destinataer.unterstuetzung_bestaetigt
|
||||
and destinataer.standard_konto
|
||||
and destinataer.vierteljaehrlicher_betrag
|
||||
and destinataer.vierteljaehrlicher_betrag > 0
|
||||
):
|
||||
from decimal import Decimal
|
||||
from stiftung.models import DestinataerUnterstuetzung
|
||||
|
||||
heute = timezone.now().date()
|
||||
beschreibung = f"Vierteljährliche Vorauszahlung für {destinataer.get_full_name()}"
|
||||
# ensure only one upcoming planned entry; update if one exists
|
||||
existing = (
|
||||
DestinataerUnterstuetzung.objects.filter(
|
||||
destinataer=destinataer, status="geplant"
|
||||
)
|
||||
.order_by("faellig_am")
|
||||
.first()
|
||||
)
|
||||
if existing:
|
||||
existing.konto = destinataer.standard_konto
|
||||
existing.betrag = Decimal(destinataer.vierteljaehrlicher_betrag)
|
||||
existing.faellig_am = heute
|
||||
existing.beschreibung = beschreibung
|
||||
existing.save()
|
||||
else:
|
||||
DestinataerUnterstuetzung.objects.create(
|
||||
destinataer=destinataer,
|
||||
konto=destinataer.standard_konto,
|
||||
betrag=Decimal(destinataer.vierteljaehrlicher_betrag),
|
||||
faellig_am=heute,
|
||||
status="geplant",
|
||||
beschreibung=beschreibung,
|
||||
)
|
||||
|
||||
return JsonResponse({
|
||||
'success': True,
|
||||
'message': f'Destinatär "{destinataer.get_full_name()}" wurde erfolgreich aktualisiert.'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': f'Fehler beim Speichern: {str(e)}'
|
||||
})
|
||||
else:
|
||||
# Return form errors for AJAX requests
|
||||
errors = []
|
||||
for field, field_errors in form.errors.items():
|
||||
for error in field_errors:
|
||||
errors.append(f'{form[field].label}: {error}')
|
||||
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': 'Formular enthält Fehler: ' + '; '.join(errors)
|
||||
})
|
||||
|
||||
# Handle regular form submission
|
||||
if form.is_valid():
|
||||
destinataer = form.save()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user