fix graphs: grouping and ignore deleted expenses

This commit is contained in:
Peter 2023-09-21 11:08:34 +08:00
parent 0a28f2f27d
commit 33c3e42864
4 changed files with 14 additions and 4 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
etc/ etc/
test.py test.py
localhost_config.py
static/
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files

View File

@ -14,9 +14,10 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 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.contrib import admin
from django.urls import include, path from django.urls import include, path
from expenses.models import Expense, Timesheet from expenses.models import Expense, Timesheet
@ -25,6 +26,8 @@ urlpatterns = [
path("admin/summary/", include("summary.urls")), path("admin/summary/", include("summary.urls")),
path("admin/", admin.site.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.site_header = "Yet another money manager"
admin.site.index_title = f"Handling {Expense.objects.all().count() + Timesheet.objects.all().count()} documents..." admin.site.index_title = f"Handling {Expense.objects.all().count() + Timesheet.objects.all().count()} documents..."

View File

@ -114,7 +114,7 @@ class TimesheetAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin):
earliest = min([x.shift_start for x in queryset]).replace(day=1) earliest = min([x.shift_start for x in queryset]).replace(day=1)
expenses_in_range = Expense.objects.filter( expenses_in_range = Expense.objects.filter(
date__range=[earliest, timezone.now()] date__range=[earliest, timezone.now()], deleted=False
) )
labels = [] labels = []
@ -200,7 +200,7 @@ class ExpenseAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin):
expenses = { expenses = {
k: { k: {
"label": k, "label": k,
"data": [0], "data": [],
"backgroundColor": f"#{random.Random(x=1).randrange(0x1000000):06x}", "backgroundColor": f"#{random.Random(x=1).randrange(0x1000000):06x}",
} }
for k in set([x.category.name for x in queryset]) for k in set([x.category.name for x in queryset])
@ -218,6 +218,8 @@ class ExpenseAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin):
) )
) )
expenses_total.append(0) expenses_total.append(0)
for k in expenses.keys():
expenses[k]["data"].append(0)
for x in queryset: for x in queryset:
if x.date.year == b.year and x.date.month == b.month: if x.date.year == b.year and x.date.month == b.month:
expenses_total[-1] += convert_money(x.price, "AUD").amount expenses_total[-1] += convert_money(x.price, "AUD").amount
@ -225,7 +227,6 @@ class ExpenseAdmin(AdminBase, AdminChartMixin, ImportExportModelAdmin):
x.price, "AUD" x.price, "AUD"
).amount ).amount
print(list(expenses))
return { return {
"labels": labels, "labels": labels,
"datasets": [ "datasets": [

4
run-local.sh Executable file
View File

@ -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