From: Gael Le Mignot Date: Tue, 19 Sep 2023 09:32:08 +0000 (+0200) Subject: Handling periods with year in name for payment X-Git-Tag: 2.9.0~54 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=7bf19687dd1b33078dec349f1f908b0f197f97e7;p=teleforma.git Handling periods with year in name for payment --- diff --git a/teleforma/management/commands/teleforma-send-payment-emails.py b/teleforma/management/commands/teleforma-send-payment-emails.py index 84edd039..7b7fc9d1 100644 --- a/teleforma/management/commands/teleforma-send-payment-emails.py +++ b/teleforma/management/commands/teleforma-send-payment-emails.py @@ -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) diff --git a/teleforma/models/core.py b/teleforma/models/core.py old mode 100755 new mode 100644 diff --git a/teleforma/models/crfpa.py b/teleforma/models/crfpa.py old mode 100755 new mode 100644 index 714db22a..405f5eb6 --- a/teleforma/models/crfpa.py +++ b/teleforma/models/crfpa.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- """ teleforma @@ -34,6 +33,7 @@ # Author: Guillaume Pellerin """ +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))