First draft of reminder mail for negative K-Psul accounts

This commit is contained in:
Alseidon 2021-02-23 23:26:25 +01:00 committed by Martin Pépin
parent f086140dad
commit d8cabda678
No known key found for this signature in database
GPG key ID: E7520278B1774448
5 changed files with 95 additions and 0 deletions

View file

@ -204,6 +204,9 @@ MAIL_DATA = {
"REPLYTO": "cof@ens.fr",
},
"rappels": {"FROM": "Le BdA <bda@ens.fr>", "REPLYTO": "Le BdA <bda@ens.fr>"},
"rappel_negatif": {
"FROM": "La K-Fêt <k-fet@ens.fr>",
},
"revente": {
"FROM": "BdA-Revente <bda-revente@ens.fr>",
"REPLYTO": "BdA-Revente <bda-revente@ens.fr>",

View file

@ -0,0 +1,41 @@
"""
Gestion en ligne de commande des mails de rappel K-Fet.
"""
from datetime import timedelta
from django.core.management.base import BaseCommand
from django.utils import timezone
from kfet.models import AccountNegative
class Command(BaseCommand):
help = (
"Envoie un mail de rappel aux personnes en négatif.\n"
"Envoie un mail au bout de 24h, puis un mail par semaine."
)
leave_locale_alone = True
def handle(self, *args, **options):
now = timezone.now()
first_delay = timedelta(days=1)
periodic_delay = timedelta(weeks=1)
accounts_first_mail = (
AccountNegative.objects.filter(start__lt=now - first_delay)
.filter(last_rappel__isnull=True)
.all()
)
accounts_periodic_mail = (
AccountNegative.objects.filter(last_rappel__isnull=False)
.filter(last_rappel__lt=now - periodic_delay)
.all()
)
for account in accounts_first_mail:
account.send_rappel()
self.stdout.write("Mail de rappel pour %s envoyé avec succès." % account)
for account in accounts_periodic_mail:
account.send_rappel()
self.stdout.write("Mail de rappel pour %s envoyé avec succès." % account)
if (not accounts_first_mail) and (not accounts_periodic_mail):
self.stdout.write("Aucun mail à envoyer.")

View file

@ -0,0 +1,20 @@
# Generated by Django 2.2.17 on 2021-02-23 21:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("kfet", "0079_auto_20210627_0022"),
]
operations = [
migrations.AddField(
model_name="accountnegative",
name="last_rappel",
field=models.DateTimeField(
blank=True, null=True, verbose_name="Mail de rappel envoyé"
),
),
]

View file

@ -1,9 +1,12 @@
import re
from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.core.validators import RegexValidator
from django.db import models, transaction
from django.db.models import F
from django.template import loader
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@ -285,10 +288,30 @@ class AccountNegative(models.Model):
)
start = models.DateTimeField(blank=True, null=True, default=None)
end = models.DateTimeField(blank=True, null=True, default=None)
last_rappel = models.DateTimeField("Mail de rappel envoyé", blank=True, null=True)
class Meta:
permissions = (("view_negs", "Voir la liste des négatifs"),)
def send_rappel(self):
"""
Envoie un mail de rappel signalant que la personne est en négatif.
"""
# On envoie le mail
send_mail(
"Compte K-Psul négatif",
loader.render_to_string(
"kfet/mails/rappel.txt",
context={"account": self.account, "start_date": self.start},
),
settings.MAIL_DATA["rappel_negatif"]["FROM"],
[self.account.email],
)
# On enregistre le fait que l'envoi a bien eu lieu
self.last_rappel = timezone.now()
self.save()
return
class CheckoutQuerySet(models.QuerySet):
def is_valid(self):

View file

@ -0,0 +1,8 @@
Bonjour {{ account.first_name }},
Nous te rappelons que tu es en négatif de {{ account.balance }}€ depuis le {{ start_date }}.
N'oublie pas de régulariser ta situation au plus vite.
En espérant te revoir très bientôt,
--
L'équipe K-Fêt