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 %} +