Fix quarterly tracking visibility and prevent duplicate support payments

🎯 Key Changes:
- Quarterly tracking now always visible (removed studiennachweis_erforderlich condition)
- Removed automatic support payment creation when 'Unterstützung bestätigt' checkbox is checked
- Support payments now ONLY created through quarterly confirmation approval workflow
- Updated auto-creation logic to create quarterly confirmations for ALL destinataers
- Updated 'no quarterly confirmations' message to be more user-friendly

🚫 Duplicate Prevention:
- No more duplicate destinataer entries in Unterstützungen list
- Single source of truth: quarterly confirmation system controls support payment creation

📋 Template Analysis:
- Reviewed all if/else statements in quarterly tracking section
- Kept all functional logic (status checks, file existence, permissions)
- Removed only the visibility-controlling conditions

 Result:
- Quarterly tracking always visible regardless of study proof requirements
- Clean separation between 'Unterstützung bestätigt' checkbox and support payment creation
- Eliminates the duplicate destinataer issue reported by user
This commit is contained in:
2025-09-28 19:51:22 +02:00
parent 4752735357
commit 994eb789b7
2 changed files with 12 additions and 86 deletions

View File

@@ -1241,12 +1241,12 @@ def destinataer_detail(request, pk):
jahr__in=[current_year, current_year + 1]
).order_by('-jahr', '-quartal')
# Create missing quarterly confirmations for current year if destinataer requires study proof
if destinataer.studiennachweis_erforderlich:
for quartal in range(1, 5): # Q1-Q4
nachweis, created = VierteljahresNachweis.get_or_create_for_period(
destinataer, current_year, quartal
)
# Create missing quarterly confirmations for current year
# Quarterly tracking is now always available regardless of study proof requirements
for quartal in range(1, 5): # Q1-Q4
nachweis, created = VierteljahresNachweis.get_or_create_for_period(
destinataer, current_year, quartal
)
# Reload to get any newly created confirmations
quarterly_confirmations = VierteljahresNachweis.objects.filter(
@@ -1304,42 +1304,8 @@ def destinataer_update(request, pk):
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,
)
# Note: Support payments are now only created through quarterly confirmations
# No automatic creation when unterstuetzung_bestaetigt is checked
return JsonResponse({
'success': True,
@@ -1366,46 +1332,8 @@ def destinataer_update(request, pk):
# Handle regular form submission
if form.is_valid():
destinataer = form.save()
try:
# 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,
)
except Exception:
pass
# Note: Support payments are now only created through quarterly confirmations
# No automatic creation when unterstuetzung_bestaetigt is checked
messages.success(
request,
f'Destinatär "{destinataer.get_full_name()}" wurde erfolgreich aktualisiert.',

View File

@@ -459,7 +459,6 @@
</div>
<!-- Quarterly Confirmations -->
{% if destinataer.studiennachweis_erforderlich %}
<div class="card shadow mb-4">
<div class="card-header bg-primary text-white">
<div class="d-flex justify-content-between align-items-center">
@@ -818,13 +817,12 @@
{% else %}
<div class="text-center py-4">
<i class="fas fa-calendar-check fa-3x text-muted mb-3"></i>
<h5 class="text-muted">Keine vierteljährlichen Nachweise</h5>
<p class="text-muted">Nachweise werden automatisch erstellt, wenn Studiennachweise erforderlich sind.</p>
<h5 class="text-muted">Keine vierteljährlichen Nachweise vorhanden</h5>
<p class="text-muted">Klicken Sie auf "Quartal hinzufügen", um einen neuen Nachweis zu erstellen.</p>
</div>
{% endif %}
</div>
</div>
{% endif %}
<!-- Notes Section -->
<div class="card shadow mb-4">