From 863d7a936847a8f95ecfbed18b84bb949bce0b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 22 Mar 2023 01:02:09 +0800 Subject: [PATCH] Simplified the "can_delete" pseudo property of the JournalEntry data model. SQLAlchemy caches the query result. There is no need to cache the result again. --- src/accounting/models.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/accounting/models.py b/src/accounting/models.py index c447623..8dea8bf 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -618,14 +618,10 @@ class JournalEntry(db.Model): :return: True if the journal entry can be deleted, or False otherwise. """ - if not hasattr(self, "__can_delete"): - def has_offset() -> bool: - for line_item in self.line_items: - if len(line_item.offsets) > 0: - return True + for line_item in self.line_items: + if len(line_item.offsets) > 0: return False - setattr(self, "__can_delete", not has_offset()) - return getattr(self, "__can_delete") + return True def delete(self) -> None: """Deletes the journal entry.