From 5ce65e36a8665ad2388190851db66e82abeb4c05 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 14 Apr 2021 15:33:06 +0200 Subject: [PATCH] In the mail that logs negative balances, add option to log old members Signed-off-by: Yohann D'ANELLO --- .../commands/send_mail_to_negative_balances.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/management/commands/send_mail_to_negative_balances.py b/management/commands/send_mail_to_negative_balances.py index efcddbb..9171600 100644 --- a/management/commands/send_mail_to_negative_balances.py +++ b/management/commands/send_mail_to_negative_balances.py @@ -1,7 +1,7 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from datetime import date +from datetime import date, timedelta from django.core.mail import send_mail from django.core.management import BaseCommand @@ -17,12 +17,22 @@ class Command(BaseCommand): parser.add_argument("--spam", "-s", action='store_true', help="Spam negative users") parser.add_argument("--report", "-r", action='store_true', help="Report the list of negative users to admins") parser.add_argument("--negative-amount", "-n", action='store', type=int, default=1000, - help="Maximum amount to be considered as very negative") + help="Maximum amount to be considered as very negative (inclusive)") + parser.add_argument("--add-years", "-y", action='store', type=int, default=0, + help="Add also people that have a negative balance since N years " + "(default to only active members)") def handle(self, *args, **options): activate('fr') + + if options['negative_amount'] == 0: + # Don't log empty notes + options['negative_amount'] = 0.01 + notes = Note.objects.filter( - Q(noteuser__user__memberships__date_end__gte=date.today()) | Q(noteclub__isnull=False), + Q(noteuser__user__memberships__date_end__gte= + date.today() - timedelta(days=int(365.25 * options['add_years']))) + | Q(noteclub__isnull=False), balance__lte=-options["negative_amount"], is_active=True, ).order_by('balance').distinct().all()