1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-06-30 02:01:07 +02:00

Adapt verbosity of some scripts

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
2021-04-14 15:18:24 +02:00
parent 13322189dc
commit cf8b05d20a
5 changed files with 20 additions and 15 deletions

View File

@ -23,10 +23,11 @@ class Command(BaseCommand):
if options["sum_all"]:
s = Note.objects.aggregate(Sum("balance"))["balance__sum"]
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
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()
if options["check_all"]:
@ -42,19 +43,13 @@ class Command(BaseCommand):
.annotate(total=F("quantity") * F("amount")).aggregate(Sum("total"))["total__sum"] or 0
calculated_balance = incoming - outcoming
if calculated_balance != balance:
err_log += self.style.NOTICE("LA SOMME DES TRANSACTIONS DE LA NOTE {} NE CORRESPOND PAS "
"AVEC LE MONTANT RÉEL".format(str(note))) + "\n"
err_log += self.style.NOTICE("Attendu : {}, calculé : {}"
.format(pretty_money(balance), pretty_money(calculated_balance))) + "\n"
self.stderr.write(self.style.NOTICE(f"LA SOMME DES TRANSACTIONS DE LA NOTE {note} NE CORRESPOND PAS "
"AVEC LE MONTANT RÉEL"))
self.stderr.write(self.style.NOTICE(f"Attendu : {pretty_money(balance)}, "
f"calculé : {pretty_money(calculated_balance)}"))
if options["fix"]:
note.balance = calculated_balance
note.save()
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)