Merge branch 'Mails_rappel_kfet' into 'master'
Reminder mails for negative K-Psul accounts See merge request klub-dev-ens/gestioCOF!492
This commit is contained in:
commit
77aa269c90
6 changed files with 100 additions and 0 deletions
|
@ -29,6 +29,7 @@ adhérents ni des cotisations.
|
||||||
|
|
||||||
### K-Fêt
|
### K-Fêt
|
||||||
|
|
||||||
|
- Ajoute de mails de rappels pour les comptes en négatif
|
||||||
- La recherche de comptes sur K-Psul remarche normalement
|
- La recherche de comptes sur K-Psul remarche normalement
|
||||||
- Le pointeur de la souris change de forme quand on survole un item d'autocomplétion
|
- Le pointeur de la souris change de forme quand on survole un item d'autocomplétion
|
||||||
- Modification du gel de compte:
|
- Modification du gel de compte:
|
||||||
|
|
|
@ -204,6 +204,9 @@ MAIL_DATA = {
|
||||||
"REPLYTO": "cof@ens.fr",
|
"REPLYTO": "cof@ens.fr",
|
||||||
},
|
},
|
||||||
"rappels": {"FROM": "Le BdA <bda@ens.fr>", "REPLYTO": "Le BdA <bda@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": {
|
"revente": {
|
||||||
"FROM": "BdA-Revente <bda-revente@ens.fr>",
|
"FROM": "BdA-Revente <bda-revente@ens.fr>",
|
||||||
"REPLYTO": "BdA-Revente <bda-revente@ens.fr>",
|
"REPLYTO": "BdA-Revente <bda-revente@ens.fr>",
|
||||||
|
|
41
kfet/management/commands/sendrappelsnegatifs.py
Normal file
41
kfet/management/commands/sendrappelsnegatifs.py
Normal 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 neg in accounts_first_mail:
|
||||||
|
neg.send_rappel()
|
||||||
|
self.stdout.write(f"Mail de rappel pour {neg.account} envoyé avec succès.")
|
||||||
|
for neg in accounts_periodic_mail:
|
||||||
|
neg.send_rappel()
|
||||||
|
self.stdout.write("Mail de rappel pour {neg.account} envoyé avec succès.")
|
||||||
|
if (not accounts_first_mail) and (not accounts_periodic_mail):
|
||||||
|
self.stdout.write("Aucun mail à envoyer.")
|
20
kfet/migrations/0080_accountnegative_last_rappel.py
Normal file
20
kfet/migrations/0080_accountnegative_last_rappel.py
Normal 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é"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,9 +1,12 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.mail import send_mail
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
|
from django.template import loader
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
@ -285,10 +288,34 @@ class AccountNegative(models.Model):
|
||||||
)
|
)
|
||||||
start = models.DateTimeField(blank=True, null=True, default=None)
|
start = models.DateTimeField(blank=True, null=True, default=None)
|
||||||
end = 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:
|
class Meta:
|
||||||
permissions = (("view_negs", "Voir la liste des négatifs"),)
|
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,
|
||||||
|
"neg_amount": -self.account.balance,
|
||||||
|
"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):
|
class CheckoutQuerySet(models.QuerySet):
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
|
|
8
kfet/templates/kfet/mails/rappel.txt
Normal file
8
kfet/templates/kfet/mails/rappel.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Bonjour {{ account.first_name }},
|
||||||
|
|
||||||
|
Nous te rappelons que tu es en négatif de {{ neg_amount }}€ 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
|
Loading…
Reference in a new issue