Files
stiftung-management-system/check_orphaned_templates.py
Stiftung Development 35ba089a84 fix: configure CI database connection properly
- Add dotenv loading to Django settings
- Update CI workflow to use correct environment variables
- Set POSTGRES_* variables instead of DATABASE_URL
- Add environment variables to all Django management commands
- Fixes CI test failures due to database connection issues
2025-09-06 18:47:23 +02:00

33 lines
1.2 KiB
Python

#!/usr/bin/env python
import os
import django
# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
django.setup()
from stiftung.models import UnterstuetzungWiederkehrend, DestinataerUnterstuetzung
# Find orphaned templates
orphaned = []
for template in UnterstuetzungWiederkehrend.objects.all():
count = DestinataerUnterstuetzung.objects.filter(wiederkehrend_von=template).count()
if count == 0:
orphaned.append((template, count))
print(f'Verwaiste Vorlagen gefunden: {len(orphaned)}')
if orphaned:
print('Details:')
for template, count in orphaned[:10]: # Show first 10
print(f'- ID {template.id}: {template.destinataer} - {template.beschreibung} ({template.betrag}€)')
else:
print('Keine verwaisten Vorlagen!')
# Also show all templates with their payment counts
print('\n--- Alle wiederkehrende Vorlagen ---')
all_templates = UnterstuetzungWiederkehrend.objects.all()
for template in all_templates[:10]: # Show first 10
count = DestinataerUnterstuetzung.objects.filter(wiederkehrend_von=template).count()
status = "VERWAIST" if count == 0 else f"{count} Zahlungen"
print(f'ID {template.id}: {template.destinataer} - {template.beschreibung} ({template.betrag}€) - {status}')