fix the missing of checking empty queryset; add bills ordering by date
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -217,6 +217,8 @@ class Bill(models.Model):
|
||||
verbose_name = "Rechnung"
|
||||
verbose_name_plural = "Rechnungen"
|
||||
|
||||
ordering = ["-date"]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.purpose}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user