From 3b522af41bda3a851f92496cd0d3403b92700a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 7 Aug 2020 10:09:41 +0800 Subject: [PATCH] Added the is_parent_and_in_use decorated @property to the Account data model in the accounting application. --- accounting/models.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/accounting/models.py b/accounting/models.py index c9ac681..1bd0927 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -64,6 +64,7 @@ class Account(DirtyFieldsMixin, models.Model): self.is_for_debit = None self.is_for_credit = None self.is_in_use = None + self._is_parent_and_in_use = None def __str__(self): """Returns the string representation of this account.""" @@ -87,6 +88,23 @@ class Account(DirtyFieldsMixin, models.Model): "title": self.title, } + @property + def is_parent_and_in_use(self): + """Whether this is a parent account and is in use. + + Returns: + bool: True if this is a parent account and is in use, or false + otherwise + """ + if self._is_parent_and_in_use is None: + self._is_parent_and_in_use = self.child_set.count() > 0\ + and self.record_set.count() > 0 + return self._is_parent_and_in_use + + @is_parent_and_in_use.setter + def is_parent_and_in_use(self, value): + self._is_parent_and_in_use = value + class Transaction(DirtyFieldsMixin, models.Model): """An accounting transaction."""