]> git.parisson.com Git - teleforma.git/commitdiff
close accounts regarding period account closing date
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Wed, 10 Jan 2024 07:48:08 +0000 (08:48 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Wed, 10 Jan 2024 07:48:08 +0000 (08:48 +0100)
teleforma/management/commands/teleforma-deactivate-students.py

index a366a0a58c87f9bdb4f94b7a30541f80861c5864..3e0c48c0b3f53ab6b1293ec1a2fa021821896caa 100644 (file)
@@ -26,7 +26,7 @@ class Logger:
 
 
 class Command(BaseCommand):
-    help = "Deactivate student user for a given period"
+    help = "Deactivate students accounts"
     language_code = 'fr_FR'
 
     def add_arguments(self, parser):
@@ -34,18 +34,20 @@ class Command(BaseCommand):
 
     def handle(self, *args, **options):
         log_file = args[-1]
-        period_name = args[-2]
 
         logger = Logger(log_file)
         logger.logger.info('########### Processing #############')
 
-        period = Period.objects.get(name=period_name)
+        today = datetime.date.today()
         students = Student.objects.filter(period=period)
         translation.activate(self.language_code)
 
         for student in students:
             if student.user:
-                if student.is_subscribed and student.confirmation_sent and student.user.email and student.user.is_active:
+                if student.is_subscribed and student.confirmation_sent and \
+                    student.user.email and student.user.is_active and \
+                    student.period.date_close_accounts <= today:
+
                     student.user.is_active = False
                     student.user.save()
                     logger.logger.info('deactivated : ' + student.user.username)