Added the is_parent_and_in_use decorated @property to the Account data model in the accounting application.

This commit is contained in:
依瑪貓 2020-08-07 10:09:41 +08:00
parent 4eb2391fd8
commit 3b522af41b

View File

@ -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."""