Added the is_parent_and_in_use decorated @property to the Account data model in the accounting application.
This commit is contained in:
		| @@ -64,6 +64,7 @@ class Account(DirtyFieldsMixin, models.Model): | |||||||
|         self.is_for_debit = None |         self.is_for_debit = None | ||||||
|         self.is_for_credit = 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): |     def __str__(self): | ||||||
|         """Returns the string representation of this account.""" |         """Returns the string representation of this account.""" | ||||||
| @@ -87,6 +88,23 @@ class Account(DirtyFieldsMixin, models.Model): | |||||||
|             "title": self.title, |             "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): | class Transaction(DirtyFieldsMixin, models.Model): | ||||||
|     """An accounting transaction.""" |     """An accounting transaction.""" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user