From 24fb6cefb9c8653a5c2302323d5c03956ae874a7 Mon Sep 17 00:00:00 2001 From: David Martin Date: Thu, 24 Aug 2017 20:51:09 +1000 Subject: [PATCH] Add config settings to set the start and the end of the financial year. Now we allow to filter for any financial year dates. Note that we also only show the financial year filter if the dates are actually set. --- paperless.conf.example | 6 ++++++ src/documents/admin.py | 12 +++++++++--- src/paperless/settings.py | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/paperless.conf.example b/paperless.conf.example index a17aac327..bb8259348 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -162,6 +162,12 @@ PAPERLESS_PASSPHRASE="secret" #PAPERLESS_TIME_ZONE=UTC +# If set, Paperless will show document filters per financial year. +# The dates must be in the format "mm-dd", for example "07-15" for July 15. +#PAPERLESS_FINANCIAL_YEAR_START="mm-dd" +#PAPERLESS_FINANCIAL_YEAR_END="mm-dd" + + # The number of items on each page in the web UI. This value must be a # positive integer, but if you don't define one in paperless.conf, a default of # 100 will be used. diff --git a/src/documents/admin.py b/src/documents/admin.py index 4304293f0..17f78ffb3 100644 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -41,12 +41,14 @@ class FinancialYearFilter(admin.SimpleListFilter): def _fy_start(self, year): """Return date of the start of financial year for the given year.""" - fy_start = "{}-07-01".format(str(year)) + assert settings.FY_START + fy_start = "{}-{}".format(str(year), settings.FY_START) return datetime.strptime(fy_start, "%Y-%m-%d").date() def _fy_end(self, year): """Return date of the end of financial year for the given year.""" - fy_end = "{}-06-30".format(str(year)) + assert settings.FY_END + fy_end = "{}-{}".format(str(year), settings.FY_END) return datetime.strptime(fy_end, "%Y-%m-%d").date() def _determine_fy(self, date): @@ -105,7 +107,11 @@ class DocumentAdmin(CommonAdmin): search_fields = ("correspondent__name", "title", "content") list_display = ("title", "created", "thumbnail", "correspondent", "tags_") - list_filter = ("tags", "correspondent", FinancialYearFilter, MonthListFilter) + list_filter = ("tags", "correspondent") + if settings.FY_START and settings.FY_END: + list_filter += (FinancialYearFilter,) + list_filter += (MonthListFilter,) + ordering = ["-created", "correspondent"] def has_add_permission(self, request): diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 2e525ae41..f7b2244a7 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -254,3 +254,6 @@ POST_CONSUME_SCRIPT = os.getenv("PAPERLESS_POST_CONSUME_SCRIPT") # positive integer, but if you don't define one in paperless.conf, a default of # 100 will be used. PAPERLESS_LIST_PER_PAGE = int(os.getenv("PAPERLESS_LIST_PER_PAGE", 100)) + +FY_START = os.getenv("PAPERLESS_FINANCIAL_YEAR_START") +FY_END = os.getenv("PAPERLESS_FINANCIAL_YEAR_END")