From 734cd2320b609be3188a15e7b93ee6689177dab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 8 Aug 2020 15:18:39 +0800 Subject: [PATCH] Added the view of the account details in the accounting applications. --- accounting/models.py | 18 +- .../templates/accounting/account_detail.html | 173 ++++++++++++++++++ accounting/urls.py | 3 +- accounting/views.py | 10 +- 4 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 accounting/templates/accounting/account_detail.html diff --git a/accounting/models.py b/accounting/models.py index 1bd0927..c9e606c 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -63,7 +63,7 @@ class Account(DirtyFieldsMixin, models.Model): self.amount = None self.is_for_debit = None self.is_for_credit = None - self.is_in_use = None + self._is_in_use = None self._is_parent_and_in_use = None def __str__(self): @@ -105,6 +105,22 @@ class Account(DirtyFieldsMixin, models.Model): def is_parent_and_in_use(self, value): self._is_parent_and_in_use = value + @property + def is_in_use(self): + """Whether this account is in use. + + Returns: + bool: True if this account is in use, or false otherwise. + """ + if self._is_in_use is None: + self._is_in_use = self.child_set.count() > 0\ + or self.record_set.count() > 0 + return self._is_in_use + + @is_in_use.setter + def is_in_use(self, value): + self._is_in_use = value + class Transaction(DirtyFieldsMixin, models.Model): """An accounting transaction.""" diff --git a/accounting/templates/accounting/account_detail.html b/accounting/templates/accounting/account_detail.html new file mode 100644 index 0000000..05192c3 --- /dev/null +++ b/accounting/templates/accounting/account_detail.html @@ -0,0 +1,173 @@ +{% extends "base.html" %} +{% comment %} +The Mia Accounting Application +account_detail.html: The template for the account detail + + Copyright (c) 2020 imacat. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Author: imacat@mail.imacat.idv.tw (imacat) +First written: 2020/8/8 +{% endcomment %} +{% load static %} +{% load i18n %} +{% load mia_core %} +{% load accounting %} + +{% block settings %} + {% setvar "title" account %} +{% endblock %} + +{% block content %} + +{% if account.is_parent_and_in_use %} +
+ + {{ _("Error:")|force_escape }} {{ _("The account is a parent account but is also used in the accounting records.")|force_escape }} +
+{% endif %} + + +
+ {% csrf_token %} + + +
+ +
+ + + {{ _("Back")|force_escape }} + + + + {{ _("Setting")|force_escape }} + + {% if not account.is_in_use %} + + {% else %} + + + {{ _("Ledger")|force_escape }} + + {% endif %} +
+ + +
+ {% if account.is_in_use %} + + {% else %} + + {% endif %} +
+ +
+
{{ _("Parent Account:")|force_escape }}
+
+ {% if account.parent %} + {{ account.parent }} + {% else %} + {{ _("Topmost")|force_escape }} + {% endif %} +
+
+ +
+
{{ _("Code:")|force_escape }}
+
{{ account.code }}
+
+ +
+
{{ _("Title:")|force_escape }}
+
{{ account.title }}
+
+ +
+
{{ _("Child Accounts:")|force_escape }}
+
+ {% for child in account.child_set.all %} + + {{ child }} + + {% empty %} + {{ _("This subject is an end-point subject.")|force_escape }} + {% endfor %} +
+
+ +
+
{{ _("Created at:")|force_escape }}
+
{{ account.created_at }}
+
+ +
+
{{ _("Created by:")|force_escape }}
+
{{ account.created_by }}
+
+ +
+
{{ _("Updated at:")|force_escape }}
+
{{ account.updated_at }}
+
+ +
+
{{ _("Updated by:")|force_escape }}
+
{{ account.updated_by }}
+
+ +{% endblock %} diff --git a/accounting/urls.py b/accounting/urls.py index d6dfb43..e9da099 100644 --- a/accounting/urls.py +++ b/accounting/urls.py @@ -101,9 +101,8 @@ urlpatterns = [ mia_core_views.todo, name="accounts.store"), path("accounts/options", views.account_options, name="accounts.options"), - # TODO: To be done path("accounts/", - mia_core_views.todo, name="accounts.show"), + views.AccountView.as_view(), name="accounts.show"), # TODO: To be done path("accounts//edit", mia_core_views.todo, name="accounts.edit"), diff --git a/accounting/views.py b/accounting/views.py index 030b050..6e25b94 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -34,7 +34,7 @@ from django.utils import timezone from django.utils.decorators import method_decorator from django.utils.translation import gettext as _, gettext_noop from django.views.decorators.http import require_GET, require_POST -from django.views.generic import RedirectView, ListView +from django.views.generic import RedirectView, ListView, DetailView from mia_core.digest_auth import login_required from mia_core.period import Period @@ -1045,6 +1045,14 @@ class AccountListView(ListView): context_object_name = "account_list" +@method_decorator(require_GET, name="dispatch") +@method_decorator(login_required, name="dispatch") +class AccountView(DetailView): + """The view of an account.""" + def get_object(self, queryset=None): + return self.request.resolver_match.kwargs["account"] + + @require_GET @login_required def account_options(request):