Skip to content

Commit 26c9655

Browse files
committed
(experimental) add running totals functionality
1 parent 6679767 commit 26c9655

File tree

6 files changed

+888
-2
lines changed

6 files changed

+888
-2
lines changed

hordak/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AccountAdmin(MPTTModelAdmin):
2727
"balance_sum",
2828
"income",
2929
)
30-
readonly_fields = ("balance",)
30+
readonly_fields = ("balance", "balance_sum", "income")
3131
raw_id_fields = ("parent",)
3232
search_fields = (
3333
"code",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.core.management.base import BaseCommand
2+
3+
from hordak.models import Account, RunningTotal
4+
5+
6+
class Command(BaseCommand):
7+
help = "Recalculate running totals for all accounts"
8+
9+
def handle(self, *args, **options):
10+
print("Recalculating running totals for all accounts")
11+
queryset = Account.objects.all()
12+
for account in queryset[:1000]:
13+
total = account.balance()
14+
for currency in total.currencies():
15+
RunningTotal.objects.update_or_create(
16+
account=account,
17+
currency=currency,
18+
defaults={"balance": total[currency]},
19+
)

0 commit comments

Comments
 (0)