Added the currently-specified subject to the template variables, and use it in the template.
This commit is contained in:
parent
149aa8391a
commit
fc2e89ca1a
@ -25,7 +25,7 @@ First written: 2020/7/1
|
|||||||
|
|
||||||
{% block settings %}
|
{% block settings %}
|
||||||
{% trans "Cash Account for {} in {}" context "Accounting|" as title_format %}
|
{% trans "Cash Account for {} in {}" context "Accounting|" as title_format %}
|
||||||
{% format title_format "庫存現金" period.description as title %}
|
{% format title_format subject.title_zhtw period.description as title %}
|
||||||
{% setvar "title" title %}
|
{% setvar "title" title %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ from django.urls import reverse
|
|||||||
from django.utils import dateformat
|
from django.utils import dateformat
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.timezone import localdate
|
from django.utils.timezone import localdate
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language, pgettext
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.views.decorators.http import require_GET
|
from django.views.decorators.http import require_GET
|
||||||
|
|
||||||
from accounting.models import Record, Transaction
|
from accounting.models import Record, Transaction, Subject
|
||||||
from mia_core.period import Period
|
from mia_core.period import Period
|
||||||
from mia import settings
|
from mia import settings
|
||||||
from mia_core.digest_auth import digest_login_required
|
from mia_core.digest_auth import digest_login_required
|
||||||
@ -73,11 +73,13 @@ class BaseReportView(generic.ListView):
|
|||||||
page_no (int): The specified page number
|
page_no (int): The specified page number
|
||||||
page_size (int): The specified page size
|
page_size (int): The specified page size
|
||||||
period (Period): The template period helper
|
period (Period): The template period helper
|
||||||
|
subject (Subject): The currently-specified subject
|
||||||
"""
|
"""
|
||||||
page_no = None
|
page_no = None
|
||||||
page_size = None
|
page_size = None
|
||||||
pagination = None
|
pagination = None
|
||||||
period = None
|
period = None
|
||||||
|
subject = None
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
"""Adds object_list to the context.
|
"""Adds object_list to the context.
|
||||||
@ -128,6 +130,7 @@ class BaseReportView(generic.ListView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
data = super(BaseReportView, self).get_context_data(**kwargs)
|
data = super(BaseReportView, self).get_context_data(**kwargs)
|
||||||
data["period"] = self.period
|
data["period"] = self.period
|
||||||
|
data["subject"] = self.subject
|
||||||
data["pagination_links"] = self.pagination.links
|
data["pagination_links"] = self.pagination.links
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -152,6 +155,9 @@ class CashReportView(BaseReportView):
|
|||||||
get_language(), data_start, data_end,
|
get_language(), data_start, data_end,
|
||||||
self.kwargs["period_spec"])
|
self.kwargs["period_spec"])
|
||||||
if self.kwargs["subject_code"] == "0":
|
if self.kwargs["subject_code"] == "0":
|
||||||
|
self.subject = Subject(code="0")
|
||||||
|
self.subject.title_zhtw = pgettext(
|
||||||
|
"Accounting|", "Current assets and liabilities")
|
||||||
records = Record.objects.raw(
|
records = Record.objects.raw(
|
||||||
"""SELECT r.*
|
"""SELECT r.*
|
||||||
FROM accounting_records AS r
|
FROM accounting_records AS r
|
||||||
@ -184,6 +190,8 @@ ORDER BY
|
|||||||
r.ord""",
|
r.ord""",
|
||||||
[self.period.start, self.period.end])
|
[self.period.start, self.period.end])
|
||||||
else:
|
else:
|
||||||
|
self.subject = Subject.objects.filter(
|
||||||
|
code=self.kwargs["subject_code"]).first()
|
||||||
records = Record.objects.raw(
|
records = Record.objects.raw(
|
||||||
"""SELECT r.*
|
"""SELECT r.*
|
||||||
FROM accounting_records AS r
|
FROM accounting_records AS r
|
||||||
@ -210,8 +218,8 @@ ORDER BY
|
|||||||
r.ord""",
|
r.ord""",
|
||||||
[self.period.start,
|
[self.period.start,
|
||||||
self.period.end,
|
self.period.end,
|
||||||
self.kwargs["subject_code"] + "%",
|
self.subject.code + "%",
|
||||||
self.kwargs["subject_code"] + "%"])
|
self.subject.code + "%"])
|
||||||
self.pagination = Pagination(
|
self.pagination = Pagination(
|
||||||
self.request.get_full_path(), records,
|
self.request.get_full_path(), records,
|
||||||
self.page_no, self.page_size, True)
|
self.page_no, self.page_size, True)
|
||||||
|
Loading…
Reference in New Issue
Block a user