Added the "sql_condition" method to the CurrentAccount data model to simplify the queries.

This commit is contained in:
2023-03-22 21:43:58 +08:00
parent 7e90ec5a8f
commit 0ad2ac53dd
2 changed files with 16 additions and 12 deletions

View File

@ -75,9 +75,19 @@ class CurrentAccount:
accounts: list[cls] = [cls.current_assets_and_liabilities()]
accounts.extend([CurrentAccount(x)
for x in db.session.query(Account)
.filter(sa.or_(Account.base_code.startswith("11"),
Account.base_code.startswith("12"),
Account.base_code.startswith("21"),
Account.base_code.startswith("22")))
.filter(cls.sql_condition())
.order_by(Account.base_code, Account.no)])
return accounts
@classmethod
def sql_condition(cls) -> sa.BinaryExpression:
"""Returns the SQL condition for the current assets and liabilities
accounts.
:return: The SQL condition for the current assets and liabilities
accounts.
"""
return sa.or_(Account.base_code.startswith("11"),
Account.base_code.startswith("12"),
Account.base_code.startswith("21"),
Account.base_code.startswith("22"))