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:
@@ -1241,12 +1241,12 @@ def destinataer_detail(request, pk):
|
|||||||
jahr__in=[current_year, current_year + 1]
|
jahr__in=[current_year, current_year + 1]
|
||||||
).order_by('-jahr', '-quartal')
|
).order_by('-jahr', '-quartal')
|
||||||
|
|
||||||
# Create missing quarterly confirmations for current year if destinataer requires study proof
|
# Create missing quarterly confirmations for current year
|
||||||
if destinataer.studiennachweis_erforderlich:
|
# Quarterly tracking is now always available regardless of study proof requirements
|
||||||
for quartal in range(1, 5): # Q1-Q4
|
for quartal in range(1, 5): # Q1-Q4
|
||||||
nachweis, created = VierteljahresNachweis.get_or_create_for_period(
|
nachweis, created = VierteljahresNachweis.get_or_create_for_period(
|
||||||
destinataer, current_year, quartal
|
destinataer, current_year, quartal
|
||||||
)
|
)
|
||||||
|
|
||||||
# Reload to get any newly created confirmations
|
# Reload to get any newly created confirmations
|
||||||
quarterly_confirmations = VierteljahresNachweis.objects.filter(
|
quarterly_confirmations = VierteljahresNachweis.objects.filter(
|
||||||
@@ -1304,42 +1304,8 @@ def destinataer_update(request, pk):
|
|||||||
try:
|
try:
|
||||||
destinataer = form.save()
|
destinataer = form.save()
|
||||||
|
|
||||||
# Auto-create a Destinatärunterstützung if conditions are met
|
# Note: Support payments are now only created through quarterly confirmations
|
||||||
if (
|
# No automatic creation when unterstuetzung_bestaetigt is checked
|
||||||
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({
|
return JsonResponse({
|
||||||
'success': True,
|
'success': True,
|
||||||
@@ -1366,46 +1332,8 @@ def destinataer_update(request, pk):
|
|||||||
# Handle regular form submission
|
# Handle regular form submission
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
destinataer = form.save()
|
destinataer = form.save()
|
||||||
try:
|
# Note: Support payments are now only created through quarterly confirmations
|
||||||
# Auto-create a Destinatärunterstützung if conditions are met
|
# No automatic creation when unterstuetzung_bestaetigt is checked
|
||||||
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
|
|
||||||
messages.success(
|
messages.success(
|
||||||
request,
|
request,
|
||||||
f'Destinatär "{destinataer.get_full_name()}" wurde erfolgreich aktualisiert.',
|
f'Destinatär "{destinataer.get_full_name()}" wurde erfolgreich aktualisiert.',
|
||||||
|
|||||||
@@ -459,7 +459,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Quarterly Confirmations -->
|
<!-- Quarterly Confirmations -->
|
||||||
{% if destinataer.studiennachweis_erforderlich %}
|
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
<div class="card-header bg-primary text-white">
|
<div class="card-header bg-primary text-white">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
@@ -818,13 +817,12 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<div class="text-center py-4">
|
<div class="text-center py-4">
|
||||||
<i class="fas fa-calendar-check fa-3x text-muted mb-3"></i>
|
<i class="fas fa-calendar-check fa-3x text-muted mb-3"></i>
|
||||||
<h5 class="text-muted">Keine vierteljährlichen Nachweise</h5>
|
<h5 class="text-muted">Keine vierteljährlichen Nachweise vorhanden</h5>
|
||||||
<p class="text-muted">Nachweise werden automatisch erstellt, wenn Studiennachweise erforderlich sind.</p>
|
<p class="text-muted">Klicken Sie auf "Quartal hinzufügen", um einen neuen Nachweis zu erstellen.</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- Notes Section -->
|
<!-- Notes Section -->
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user