Revised the code in the views of the accounting application.

This commit is contained in:
依瑪貓 2020-07-17 00:19:41 +08:00
parent 5855c1dd2b
commit 7f7e2c7100

View File

@ -285,13 +285,13 @@ def cash_summary(request, subject_code):
current_subject = subject current_subject = subject
if current_subject is None: if current_subject is None:
raise Http404() raise Http404()
# The SQL query
if connection.vendor == "postgresql": if connection.vendor == "postgresql":
month_definition = "CAST(DATE_TRUNC('month', t.date) AS date)" month_definition = "CAST(DATE_TRUNC('month', t.date) AS date)"
elif connection.vendor == "sqlite": elif connection.vendor == "sqlite":
month_definition = "DATE(t.date, 'start of month')" month_definition = "DATE(t.date, 'start of month')"
else: else:
month_definition = None month_definition = None
# The SQL query
if current_subject.code == "0": if current_subject.code == "0":
records = list(RecordSummary.objects.raw( records = list(RecordSummary.objects.raw(
f"""SELECT f"""SELECT
@ -470,13 +470,13 @@ def ledger_summary(request, subject_code):
current_subject = subject current_subject = subject
if current_subject is None: if current_subject is None:
raise Http404() raise Http404()
# The SQL query
if connection.vendor == "postgresql": if connection.vendor == "postgresql":
month_definition = "CAST(DATE_TRUNC('month', t.date) AS date)" month_definition = "CAST(DATE_TRUNC('month', t.date) AS date)"
elif connection.vendor == "sqlite": elif connection.vendor == "sqlite":
month_definition = "DATE(t.date, 'start of month')" month_definition = "DATE(t.date, 'start of month')"
else: else:
month_definition = None month_definition = None
# The SQL query
records = list(RecordSummary.objects.raw( records = list(RecordSummary.objects.raw(
f"""SELECT f"""SELECT
{month_definition} AS month, {month_definition} AS month,