From 2d6a06e1b256008ed1bf653cd665f985bf9d6ddb Mon Sep 17 00:00:00 2001 From: Patrick Mayr Date: Wed, 19 Nov 2025 14:15:34 +0100 Subject: [PATCH] fix the missing of checking empty queryset; add bills ordering by date --- fet2020/finance/admin.py | 9 ++++----- fet2020/finance/models.py | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fet2020/finance/admin.py b/fet2020/finance/admin.py index 936ac76c..c78bd495 100644 --- a/fet2020/finance/admin.py +++ b/fet2020/finance/admin.py @@ -103,8 +103,6 @@ class BillPeriodeFilter(admin.SimpleListFilter): return self.__lst def queryset(self, request, queryset): - qs = queryset - if self.value(): try: period = datetime.strptime(self.value()[:4], "%Y") # noqa: DTZ007 @@ -120,14 +118,15 @@ class BillPeriodeFilter(admin.SimpleListFilter): # Return bills from current period. else: - tmp_qs = queryset.order_by("-date") + if not queryset.exists(): + return queryset # Get first period. - start_year = tmp_qs.first().date.year + start_year = queryset.first().date.year # Check if date of first bill is in first half of year. If yes, start of period is the # year before. - if tmp_qs.first().date < date(start_year, 7, 1): + if queryset.first().date < date(start_year, 7, 1): start_year -= 1 start_date = date(start_year, 7, 1) diff --git a/fet2020/finance/models.py b/fet2020/finance/models.py index a3ed385c..394d8c39 100644 --- a/fet2020/finance/models.py +++ b/fet2020/finance/models.py @@ -217,6 +217,8 @@ class Bill(models.Model): verbose_name = "Rechnung" verbose_name_plural = "Rechnungen" + ordering = ["-date"] + def __str__(self): return f"{self.purpose}"