mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2025-02-23 16:41:24 +00:00
Compare commits
2 Commits
13322189dc
...
5ce65e36a8
Author | SHA1 | Date | |
---|---|---|---|
5ce65e36a8 | |||
cf8b05d20a |
@ -23,10 +23,11 @@ class Command(BaseCommand):
|
|||||||
if options["sum_all"]:
|
if options["sum_all"]:
|
||||||
s = Note.objects.aggregate(Sum("balance"))["balance__sum"]
|
s = Note.objects.aggregate(Sum("balance"))["balance__sum"]
|
||||||
if s:
|
if s:
|
||||||
err_log += self.style.NOTICE("LA SOMME DES NOTES NE VAUT PAS ZÉRO : " + pretty_money(s)) + "\n"
|
self.stderr.write(self.style.NOTICE("LA SOMME DES NOTES NE VAUT PAS ZÉRO : " + pretty_money(s)))
|
||||||
error = True
|
error = True
|
||||||
else:
|
else:
|
||||||
self.stdout.write(self.style.SUCCESS("La somme des notes vaut bien zéro."))
|
if options["verbosity"] > 0:
|
||||||
|
self.stdout.write(self.style.SUCCESS("La somme des notes vaut bien zéro."))
|
||||||
|
|
||||||
notes = Note.objects.none()
|
notes = Note.objects.none()
|
||||||
if options["check_all"]:
|
if options["check_all"]:
|
||||||
@ -42,19 +43,13 @@ class Command(BaseCommand):
|
|||||||
.annotate(total=F("quantity") * F("amount")).aggregate(Sum("total"))["total__sum"] or 0
|
.annotate(total=F("quantity") * F("amount")).aggregate(Sum("total"))["total__sum"] or 0
|
||||||
calculated_balance = incoming - outcoming
|
calculated_balance = incoming - outcoming
|
||||||
if calculated_balance != balance:
|
if calculated_balance != balance:
|
||||||
err_log += self.style.NOTICE("LA SOMME DES TRANSACTIONS DE LA NOTE {} NE CORRESPOND PAS "
|
self.stderr.write(self.style.NOTICE(f"LA SOMME DES TRANSACTIONS DE LA NOTE {note} NE CORRESPOND PAS "
|
||||||
"AVEC LE MONTANT RÉEL".format(str(note))) + "\n"
|
"AVEC LE MONTANT RÉEL"))
|
||||||
err_log += self.style.NOTICE("Attendu : {}, calculé : {}"
|
self.stderr.write(self.style.NOTICE(f"Attendu : {pretty_money(balance)}, "
|
||||||
.format(pretty_money(balance), pretty_money(calculated_balance))) + "\n"
|
f"calculé : {pretty_money(calculated_balance)}"))
|
||||||
if options["fix"]:
|
if options["fix"]:
|
||||||
note.balance = calculated_balance
|
note.balance = calculated_balance
|
||||||
note.save()
|
note.save()
|
||||||
error = True
|
error = True
|
||||||
|
|
||||||
if error:
|
|
||||||
self.stderr.write(err_log)
|
|
||||||
if options["mail"]:
|
|
||||||
send_mail("[Note Kfet] La base de données n'est pas consistante", err_log,
|
|
||||||
"NoteKfet2020 <notekfet2020@crans.org>", ["respo-info.bde@lists.crans.org"])
|
|
||||||
|
|
||||||
exit(1 if error else 0)
|
exit(1 if error else 0)
|
||||||
|
@ -19,7 +19,8 @@ class Command(BaseCommand):
|
|||||||
for code, _ in settings.LANGUAGES:
|
for code, _ in settings.LANGUAGES:
|
||||||
if code == settings.LANGUAGE_CODE:
|
if code == settings.LANGUAGE_CODE:
|
||||||
continue
|
continue
|
||||||
self.stdout.write(f"Generate {code} javascript localization file")
|
if kwargs["verbosity"] > 0:
|
||||||
|
self.stdout.write(f"Generate {code} javascript localization file")
|
||||||
with translation.override(code):
|
with translation.override(code):
|
||||||
resp = JavaScriptCatalog().get(None, packages="member+note")
|
resp = JavaScriptCatalog().get(None, packages="member+note")
|
||||||
if not os.path.isdir(kwargs["out"] + "/js/jsi18n"):
|
if not os.path.isdir(kwargs["out"] + "/js/jsi18n"):
|
||||||
|
@ -25,6 +25,10 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
# TODO: Improve the mailing list extraction system, and link it automatically with Mailman.
|
# TODO: Improve the mailing list extraction system, and link it automatically with Mailman.
|
||||||
|
|
||||||
|
if options['verbosity'] == 0:
|
||||||
|
# This is useless, but this what the user asked.
|
||||||
|
return
|
||||||
|
|
||||||
if options["type"] == "members":
|
if options["type"] == "members":
|
||||||
for membership in Membership.objects.filter(
|
for membership in Membership.objects.filter(
|
||||||
club__name="BDE",
|
club__name="BDE",
|
||||||
|
@ -16,7 +16,11 @@ class Command(BaseCommand):
|
|||||||
user = User.objects.get(username=uname)
|
user = User.objects.get(username=uname)
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
if kwargs['STAFF']:
|
if kwargs['STAFF']:
|
||||||
|
if kwargs['verbosity'] > 0:
|
||||||
|
self.stdout.write(f"Add {user} to staff users...")
|
||||||
user.is_staff = True
|
user.is_staff = True
|
||||||
if kwargs['SUPER']:
|
if kwargs['SUPER']:
|
||||||
|
if kwargs['verbosity'] > 0:
|
||||||
|
self.stdout.write(f"Add {user} to superusers...")
|
||||||
user.is_superuser = True
|
user.is_superuser = True
|
||||||
user.save()
|
user.save()
|
||||||
|
@ -23,7 +23,8 @@ class Command(BaseCommand):
|
|||||||
for d in queryset.all():
|
for d in queryset.all():
|
||||||
button_id = d["template"]
|
button_id = d["template"]
|
||||||
button = TransactionTemplate.objects.get(pk=button_id)
|
button = TransactionTemplate.objects.get(pk=button_id)
|
||||||
self.stdout.write(self.style.WARNING("Highlight button {name} ({count:d} transactions)..."
|
if kwargs['verbosity'] > 0:
|
||||||
.format(name=button.name, count=d["transaction_count"])))
|
self.stdout.write(self.style.WARNING("Highlight button {name} ({count:d} transactions)..."
|
||||||
|
.format(name=button.name, count=d["transaction_count"])))
|
||||||
button.highlighted = True
|
button.highlighted = True
|
||||||
button.save()
|
button.save()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# 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.mail import send_mail
|
||||||
from django.core.management import BaseCommand
|
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("--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("--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,
|
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):
|
def handle(self, *args, **options):
|
||||||
activate('fr')
|
activate('fr')
|
||||||
|
|
||||||
|
if options['negative_amount'] == 0:
|
||||||
|
# Don't log empty notes
|
||||||
|
options['negative_amount'] = 0.01
|
||||||
|
|
||||||
notes = Note.objects.filter(
|
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"],
|
balance__lte=-options["negative_amount"],
|
||||||
is_active=True,
|
is_active=True,
|
||||||
).order_by('balance').distinct().all()
|
).order_by('balance').distinct().all()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user