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}"