]> git.parisson.com Git - teleforma.git/commitdiff
Handling periods with year in name for payment
authorGael Le Mignot <gael@pilotsystems.net>
Tue, 19 Sep 2023 09:32:08 +0000 (11:32 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Tue, 19 Sep 2023 09:32:08 +0000 (11:32 +0200)
teleforma/management/commands/teleforma-send-payment-emails.py
teleforma/models/core.py [changed mode: 0755->0644]
teleforma/models/crfpa.py [changed mode: 0755->0644]

index 84edd0399000f6aa1b1a2bfc374b1cc07253051e..7b7fc9d14bbae26bc50deb87fafdd15cf50ed016 100644 (file)
@@ -6,8 +6,10 @@ from django.template.loader import render_to_string
 from django.core.mail import send_mail
 from django.utils import translation
 from teleforma.models import *
+import re
 import logging
 import datetime
+import time
 from django.core.exceptions import ObjectDoesNotExist
 
 class Logger:
@@ -46,7 +48,19 @@ class Command(BaseCommand):
         logger = Logger(log_file)
         logger.logger.info('########### Processing #############')
 
-        period = Period.objects.get(name=period_name)
+        cur_year = time.strftime('%Y')
+        
+        all_periods = Period.objects.all()
+        periods = []
+        for period in all_periods:
+            name = period.name
+            if re.match('^.* 20[0-9][0-9]$', name):
+                year = name[-4:]
+                if year >= cur_year:
+                    name = name[:-5]
+            if name == period_name:
+                periods.append(period)
+        logger.logger.info('##### Will handle periods %s' % ', '.join([ str(p) for p in periods ]))
         students = Student.objects.all()
         translation.activate(self.language_code)
 
@@ -59,7 +73,7 @@ class Command(BaseCommand):
                 logger.logger.warning('missing user object for %s' % student.pk)
                 continue
             
-            if student.is_subscribed and user.email and student.period == period and user.is_active :
+            if student.is_subscribed and user.email and student.period in periods and user.is_active :
                 for payment in student.payments.filter(type = 'online').exclude(online_paid = True).filter(scheduled__lte = today):
                     if payment.scheduled == today:
                         self.email(student, 'initial', payment)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 714db22..405f5eb
@@ -1,4 +1,3 @@
-#!/usr/bin/python
 # -*- coding: utf-8 -*-
 """
    teleforma
@@ -34,6 +33,7 @@
 # Author: Guillaume Pellerin <yomguy@parisson.com>
 """
 
+import re
 import datetime
 
 from django.conf import settings
@@ -323,9 +323,12 @@ class Student(models.Model):
             return datetime.date(year, month, 1) - oneday
 
         payments = None
+        period_name = period.name
+        if re.match('^.* 20[0-9][0-9]$', period_name):
+            period_name = period_name[:-5]
         # Full or partial ?
         if self.payment_schedule == 'split':
-            if period.name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
+            if period_name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
                 part = int(total * 0.25)
                 remaining = total - 3 * part
                 payments = ((remaining, tomorrow),)
@@ -341,7 +344,7 @@ class Student(models.Model):
                         # look at 01/m+1 and then remove one day
                         date = endofmonth(tomorrow.year + 1, month)
                         payments += ((part, date),)
-            elif period.name == 'Estivale':
+            elif period_name == 'Estivale':
                 part = int(total * 0.35)
                 remaining = total - 2 * part
                 payments = ((remaining, tomorrow),)
@@ -365,14 +368,14 @@ class Student(models.Model):
 
         # Handle oral date
         oral_date = None
-        if period.name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
+        if period_name in ('Semestrielle', 'Annuelle', 'Annuelle progressive'):
             if tomorrow.month <= 6:                    
                 # Late registration
                 oral_date = endofmonth(tomorrow.year, 6)
             else:
                 # Normal registration
                 oral_date = endofmonth(tomorrow.year + 1, 6)
-        elif period.name == 'Estivale':
+        elif period_name == 'Estivale':
             if tomorrow.month >= 6:
                 # Late registration
                 oral_date = endofmonth(tomorrow.year, max(tomorrow.month, 8))