75 lines
3.2 KiB
Python
75 lines
3.2 KiB
Python
"""
|
|
Script de test pour l'export des interventions en XLSX.
|
|
|
|
Ce script permet de tester rapidement l'export avec quelques interventions
|
|
sans avoir à filtrer par dates.
|
|
|
|
Usage:
|
|
python manage.py test_export_interventions
|
|
"""
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.core.management import call_command
|
|
from interventions.models import Intervention
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Teste l\'export des interventions en affichant des statistiques'
|
|
|
|
def handle(self, *args, **options):
|
|
self.stdout.write(self.style.WARNING('=== TEST DE L\'EXPORT DES INTERVENTIONS ===\n'))
|
|
|
|
# Statistiques sur les interventions
|
|
total_interventions = Intervention.objects.count()
|
|
self.stdout.write(f'Nombre total d\'interventions: {total_interventions}')
|
|
|
|
# Compter par statut
|
|
self.stdout.write('\nRépartition par statut:')
|
|
statuts = Intervention.objects.values_list('status', flat=True).distinct()
|
|
for statut in statuts:
|
|
count = Intervention.objects.filter(status=statut).count()
|
|
self.stdout.write(f' - {statut}: {count}')
|
|
|
|
# Interventions avec contrat
|
|
with_contract = Intervention.objects.exclude(contract__isnull=True).count()
|
|
self.stdout.write(f'\nInterventions avec contrat: {with_contract}')
|
|
|
|
# Interventions avec localisation
|
|
with_location = Intervention.objects.filter(locations__isnull=False).distinct().count()
|
|
self.stdout.write(f'Interventions avec localisation: {with_location}')
|
|
|
|
# Interventions avec équipement
|
|
with_asset = Intervention.objects.filter(intervention_assets__isnull=False).distinct().count()
|
|
self.stdout.write(f'Interventions avec équipement: {with_asset}')
|
|
|
|
# Interventions avec notes
|
|
with_notes = Intervention.objects.filter(notes__isnull=False).distinct().count()
|
|
self.stdout.write(f'Interventions avec notes: {with_notes}')
|
|
|
|
self.stdout.write('\n' + '='*50 + '\n')
|
|
|
|
# Demander confirmation pour l'export
|
|
if total_interventions == 0:
|
|
self.stdout.write(self.style.ERROR('Aucune intervention trouvée dans la base de données.'))
|
|
return
|
|
|
|
self.stdout.write(self.style.WARNING(
|
|
f'\nVoulez-vous exporter toutes les {total_interventions} interventions ?\n'
|
|
'Cela peut prendre un certain temps...\n'
|
|
))
|
|
|
|
confirm = input('Tapez "oui" pour continuer, ou appuyez sur Entrée pour annuler: ')
|
|
|
|
if confirm.lower() in ['oui', 'yes', 'y', 'o']:
|
|
self.stdout.write(self.style.SUCCESS('\n✓ Démarrage de l\'export...\n'))
|
|
try:
|
|
# Appeler la commande d'export
|
|
call_command('export_interventions_xlsx', output='test_export_interventions.xlsx')
|
|
self.stdout.write(self.style.SUCCESS('\n✓ Export terminé avec succès!'))
|
|
self.stdout.write(self.style.SUCCESS('✓ Fichier: test_export_interventions.xlsx'))
|
|
except Exception as e:
|
|
self.stderr.write(self.style.ERROR(f'\n✗ Erreur lors de l\'export: {e}'))
|
|
import traceback
|
|
traceback.print_exc()
|
|
else:
|
|
self.stdout.write(self.style.WARNING('Export annulé.'))
|