In the mail that logs negative balances, add option to log old members

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2021-04-14 15:33:06 +02:00
parent cf8b05d20a
commit 5ce65e36a8
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 13 additions and 3 deletions

View File

@ -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()