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.

This commit is contained in:
依瑪貓 2023-03-22 01:02:09 +08:00
parent 6fd37b21d9
commit 863d7a9368

View File

@ -618,14 +618,10 @@ class JournalEntry(db.Model):
:return: True if the journal entry can be deleted, or False otherwise. :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: for line_item in self.line_items:
if len(line_item.offsets) > 0: if len(line_item.offsets) > 0:
return True
return False return False
setattr(self, "__can_delete", not has_offset()) return True
return getattr(self, "__can_delete")
def delete(self) -> None: def delete(self) -> None:
"""Deletes the journal entry. """Deletes the journal entry.