Skip to content

Commit

Permalink
(experimental) add running totals functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Dec 20, 2022
1 parent 6679767 commit 26c9655
Show file tree
Hide file tree
Showing 6 changed files with 888 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hordak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AccountAdmin(MPTTModelAdmin):
"balance_sum",
"income",
)
readonly_fields = ("balance",)
readonly_fields = ("balance", "balance_sum", "income")
raw_id_fields = ("parent",)
search_fields = (
"code",
Expand Down
19 changes: 19 additions & 0 deletions hordak/management/commands/recalculate_running_totals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.core.management.base import BaseCommand

from hordak.models import Account, RunningTotal


class Command(BaseCommand):
help = "Recalculate running totals for all accounts"

def handle(self, *args, **options):
print("Recalculating running totals for all accounts")
queryset = Account.objects.all()
for account in queryset[:1000]:
total = account.balance()
for currency in total.currencies():
RunningTotal.objects.update_or_create(
account=account,
currency=currency,
defaults={"balance": total[currency]},
)
Loading

0 comments on commit 26c9655

Please sign in to comment.