Compare commits

..

2 Commits

Author SHA1 Message Date
Yohann D'ANELLO f41a5a32f7 Fix note balances if needed 2020-08-03 11:15:50 +02:00
Yohann D'ANELLO 7d0c94c19b 🐛 Kfet transactions should go to the Kfet note 2020-08-03 11:09:26 +02:00
2 changed files with 8 additions and 3 deletions

View File

@ -11,6 +11,7 @@ from note.templatetags.pretty_money import pretty_money
class Command(BaseCommand): class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('--sum-all', '-s', action='store_true', help='Check if the global sum is equal to zero') parser.add_argument('--sum-all', '-s', action='store_true', help='Check if the global sum is equal to zero')
parser.add_argument('--fix', '-f', action='store_true', help='Fix note balances')
def handle(self, *args, **options): def handle(self, *args, **options):
if options["sum_all"]: if options["sum_all"]:
@ -29,11 +30,14 @@ 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
outcoming = Transaction.objects.filter(valid=True, source=note)\ outcoming = Transaction.objects.filter(valid=True, source=note)\
.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
expected_balance = incoming - outcoming calculated_balance = incoming - outcoming
if expected_balance != balance: if calculated_balance != balance:
self.stderr.write(self.style.NOTICE("LA SOMME DES TRANSACTIONS DE LA NOTE {} NE CORRESPOND PAS " self.stderr.write(self.style.NOTICE("LA SOMME DES TRANSACTIONS DE LA NOTE {} NE CORRESPOND PAS "
"AVEC LE MONTANT RÉEL".format(str(note)))) "AVEC LE MONTANT RÉEL".format(str(note))))
self.stderr.write(self.style.NOTICE("Attendu : {}, calculé : {}" self.stderr.write(self.style.NOTICE("Attendu : {}, calculé : {}"
.format(pretty_money(balance), pretty_money(expected_balance)))) .format(pretty_money(balance), pretty_money(calculated_balance))))
if options["fix"]:
note.balance = calculated_balance
note.save()
error = True error = True
exit(1 if error else 0) exit(1 if error else 0)

View File

@ -236,6 +236,7 @@ class Command(ImportCommand):
(obj_dict0, (obj_dict0,
child_dict0, child_dict0,
child_transaction) = self._membership_transaction(row, obj_dict, child_dict, pk_membership) child_transaction) = self._membership_transaction(row, obj_dict, child_dict, pk_membership)
obj_dict0["destination_id"] = 6 # Kfet note id
bde_dict = { bde_dict = {
"pk": pk_membership, "pk": pk_membership,
"user_id": user_id, "user_id": user_id,