Replaced the "current_accounts" function with the "accounts" class method of the CurrentAccount data model.

This commit is contained in:
依瑪貓 2023-03-22 21:39:18 +08:00
parent 7755365467
commit 7e90ec5a8f
2 changed files with 16 additions and 17 deletions

View File

@ -27,7 +27,7 @@ from accounting.forms import CurrencyExists, AccountExists, IsDebitAccount, \
IsCreditAccount IsCreditAccount
from accounting.locale import lazy_gettext from accounting.locale import lazy_gettext
from accounting.models import Account from accounting.models import Account
from accounting.utils.current_account import CurrentAccount, current_accounts from accounting.utils.current_account import CurrentAccount
from accounting.utils.options import Options from accounting.utils.options import Options
from accounting.utils.strip_text import strip_text from accounting.utils.strip_text import strip_text
@ -240,4 +240,4 @@ class OptionForm(FlaskForm):
:return: The current accounts. :return: The current accounts.
""" """
return current_accounts() return CurrentAccount.accounts()

View File

@ -66,19 +66,18 @@ class CurrentAccount:
account.str = account.title account.str = account.title
return account return account
@classmethod
def accounts(cls) -> list[t.Self]:
"""Returns the current assets and liabilities accounts.
def current_accounts() -> list[CurrentAccount]: :return: The current assets and liabilities accounts.
"""Returns accounts for the income and expenses log. """
accounts: list[cls] = [cls.current_assets_and_liabilities()]
:return: The accounts for the income and expenses log. accounts.extend([CurrentAccount(x)
""" for x in db.session.query(Account)
accounts: list[CurrentAccount] \ .filter(sa.or_(Account.base_code.startswith("11"),
= [CurrentAccount.current_assets_and_liabilities()] Account.base_code.startswith("12"),
accounts.extend([CurrentAccount(x) Account.base_code.startswith("21"),
for x in db.session.query(Account) Account.base_code.startswith("22")))
.filter(sa.or_(Account.base_code.startswith("11"), .order_by(Account.base_code, Account.no)])
Account.base_code.startswith("12"), return accounts
Account.base_code.startswith("21"),
Account.base_code.startswith("22")))
.order_by(Account.base_code, Account.no)])
return accounts