Take non-wrapping financial years into account.

The German financial year for example goes from January to December. In
those cases we simply only show the year in the overview.
This commit is contained in:
David Martin 2017-08-25 20:27:39 +10:00
parent c65c5009e4
commit 1cd76634a3

View File

@ -49,18 +49,33 @@ class FinancialYearFilter(admin.SimpleListFilter):
fy_end = "{}-{}".format(str(year), settings.FY_END)
return datetime.strptime(fy_end, "%Y-%m-%d").date()
def _fy_does_wrap(self):
"""Return whether the financial year spans across two years."""
start = "{}".format(settings.FY_START)
start = datetime.strptime(start, "%m-%d").date()
end = "{}".format(settings.FY_END)
end = datetime.strptime(end, "%m-%d").date()
return end < start
def _determine_fy(self, date):
"""Return a (query, display) financial year tuple of the given date."""
fy_start = self._fy_start(date.year)
if date.date() >= fy_start:
query = "{}-{}".format(date.year, date.year + 1)
else:
query = "{}-{}".format(date.year - 1, date.year)
if self._fy_does_wrap():
if date.date() >= fy_start:
query = "{}-{}".format(date.year, date.year + 1)
else:
query = "{}-{}".format(date.year - 1, date.year)
# To keep it simple we use the same String for both query parameters
# and the display.
return (query, query)
# To keep it simple we use the same string for both
# query parameter and the display.
return (query, query)
else:
query = "{0}-{0}".format(date.year)
display = "{}".format(date.year)
return (query, display)
def lookups(self, request, model_admin):
if not settings.FY_START or not settings.FY_END: