From 87f383bef1698b1317f3a2d42682a7794427afc9 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sat, 18 Dec 2021 18:06:27 +0100 Subject: [PATCH 1/4] =?UTF-8?q?On=20n'envoie=20des=20mails=20de=20rappel?= =?UTF-8?q?=20que=20lorsque=20le=20n=C3=A9gatif=20est=20toujours=20d'actua?= =?UTF-8?q?lit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/sendrappelsnegatifs.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/kfet/management/commands/sendrappelsnegatifs.py b/kfet/management/commands/sendrappelsnegatifs.py index 58c47d4e..2351f68f 100644 --- a/kfet/management/commands/sendrappelsnegatifs.py +++ b/kfet/management/commands/sendrappelsnegatifs.py @@ -19,23 +19,31 @@ class Command(BaseCommand): def handle(self, *args, **options): now = timezone.now() + + # Le premier mail est envoyé après 24h de négatif, puis toutes les semaines 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() + + # On n'envoie des mails qu'aux comptes qui ont un négatif vraiment actif + # et dont la balance est négative + account_negatives = AccountNegative.objects.filter( + account__balance__lt=0 + ).exclude(end__lte=now) + + accounts_first_mail = account_negatives.filter( + start__lt=now - first_delay, last_rappel__isnull=True ) - accounts_periodic_mail = ( - AccountNegative.objects.filter(last_rappel__isnull=False) - .filter(last_rappel__lt=now - periodic_delay) - .all() + accounts_periodic_mail = account_negatives.filter( + last_rappel__isnull=False, last_rappel__lt=now - periodic_delay ) + 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): + + if not (accounts_first_mail.exists() or accounts_periodic_mail.exists()): self.stdout.write("Aucun mail à envoyer.") From 4b29097f0293374d664e070e2c34aa6350a4d16d Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 11 Jan 2022 17:52:47 +0100 Subject: [PATCH 2/4] =?UTF-8?q?On=20sauvegarde=20la=20date=20de=20fin=20du?= =?UTF-8?q?=20n=C3=A9gatif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kfet/models.py b/kfet/models.py index 7a0ec777..a71b53cd 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -260,8 +260,10 @@ class Account(models.Model): elif hasattr(self, "negative"): if self.negative.end is None: self.negative.end = timezone.now() + self.negative.save() elif timezone.now() > self.negative.end + kfet_config.cancel_duration: # Idem: on supprime le négatif après une légère période + # Nécessaire pour se souvenir du négatif après une charge annulée self.negative.delete() class UserHasAccount(Exception): From b236d6a950e7bcb10d1152dcecd74af4be41493b Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 11 Jan 2022 18:03:16 +0100 Subject: [PATCH 3/4] Si last_rappel vaut None il n'est pas inclus dans le __lt --- kfet/management/commands/sendrappelsnegatifs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/management/commands/sendrappelsnegatifs.py b/kfet/management/commands/sendrappelsnegatifs.py index 2351f68f..4e2f67c3 100644 --- a/kfet/management/commands/sendrappelsnegatifs.py +++ b/kfet/management/commands/sendrappelsnegatifs.py @@ -34,7 +34,7 @@ class Command(BaseCommand): start__lt=now - first_delay, last_rappel__isnull=True ) accounts_periodic_mail = account_negatives.filter( - last_rappel__isnull=False, last_rappel__lt=now - periodic_delay + last_rappel__lt=now - periodic_delay ) for neg in accounts_first_mail: From fcf2002cd70010a290247aaca0dd3269937fbcd4 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 11 Jan 2022 18:03:50 +0100 Subject: [PATCH 4/4] =?UTF-8?q?On=20n'affiche=20le=20n=C3=A9gatif=20que=20?= =?UTF-8?q?s'il=20existe=20vraiment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/templates/kfet/left_account.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/templates/kfet/left_account.html b/kfet/templates/kfet/left_account.html index aa22cb03..98f0aa21 100644 --- a/kfet/templates/kfet/left_account.html +++ b/kfet/templates/kfet/left_account.html @@ -53,7 +53,7 @@ - {% if account.negative %} + {% if account.negative and account.balance_ukf < 0 %}

Négatif