From 33c3e428648b9ccb45abf37e1ac3bd49172cbc4e Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 21 Sep 2023 11:08:34 +0800 Subject: [PATCH] fix graphs: grouping and ignore deleted expenses --- .gitignore | 2 ++ budget/urls.py | 5 ++++- expenses/admin.py | 7 ++++--- run-local.sh | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100755 run-local.sh diff --git a/.gitignore b/.gitignore index f91a118..46e6f80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ etc/ test.py +localhost_config.py +static/ # Byte-compiled / optimized / DLL files diff --git a/budget/urls.py b/budget/urls.py index 4012472..62bfab1 100644 --- a/budget/urls.py +++ b/budget/urls.py @@ -14,9 +14,10 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings +from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path - from expenses.models import Expense, Timesheet @@ -25,6 +26,8 @@ urlpatterns = [ path("admin/summary/", include("summary.urls")), path("admin/", admin.site.urls), ] +if not settings.DEBUG: + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) admin.site.site_header = "Yet another money manager" admin.site.index_title = f"Handling {Expense.objects.all().count() + Timesheet.objects.all().count()} documents..." diff --git a/expenses/admin.py b/expenses/admin.py index 568b0b9..bbf5ff9 100644 --- a/expenses/admin.py +++ b/expenses/admin.py @@ -114,7 +114,7 @@ class TimesheetAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin): earliest = min([x.shift_start for x in queryset]).replace(day=1) expenses_in_range = Expense.objects.filter( - date__range=[earliest, timezone.now()] + date__range=[earliest, timezone.now()], deleted=False ) labels = [] @@ -200,7 +200,7 @@ class ExpenseAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin): expenses = { k: { "label": k, - "data": [0], + "data": [], "backgroundColor": f"#{random.Random(x=1).randrange(0x1000000):06x}", } for k in set([x.category.name for x in queryset]) @@ -218,6 +218,8 @@ class ExpenseAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin): ) ) expenses_total.append(0) + for k in expenses.keys(): + expenses[k]["data"].append(0) for x in queryset: if x.date.year == b.year and x.date.month == b.month: expenses_total[-1] += convert_money(x.price, "AUD").amount @@ -225,7 +227,6 @@ class ExpenseAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin): x.price, "AUD" ).amount - print(list(expenses)) return { "labels": labels, "datasets": [ diff --git a/run-local.sh b/run-local.sh new file mode 100755 index 0000000..bda3e80 --- /dev/null +++ b/run-local.sh @@ -0,0 +1,4 @@ +#!/bin/bash +cd "$(dirname "$0")" +source ../.venv/bin/activate +python3 manage.py runserver --settings=localhost_config --insecure # Use internal static server