diff --git a/src/accounting/report/reports/income_expenses.py b/src/accounting/report/reports/income_expenses.py index cd5f5a0..a875c68 100644 --- a/src/accounting/report/reports/income_expenses.py +++ b/src/accounting/report/reports/income_expenses.py @@ -174,10 +174,7 @@ class LineItemCollector: @property def __account_condition(self) -> sa.BinaryExpression: if self.__account.code == CurrentAccount.CURRENT_AL_CODE: - return sa.or_(Account.base_code.startswith("11"), - Account.base_code.startswith("12"), - Account.base_code.startswith("21"), - Account.base_code.startswith("22")) + return CurrentAccount.sql_condition() return Account.id == self.__account.id def __get_total(self) -> ReportLineItem | None: @@ -352,10 +349,7 @@ class PageParams(BasePageParams): .join(Account)\ .filter(be(JournalEntryLineItem.currency_code == self.currency.code), - sa.or_(Account.base_code.startswith("11"), - Account.base_code.startswith("12"), - Account.base_code.startswith("21"), - Account.base_code.startswith("22")))\ + CurrentAccount.sql_condition())\ .group_by(JournalEntryLineItem.account_id) options.extend([OptionLink(str(x), income_expenses_url( diff --git a/src/accounting/utils/current_account.py b/src/accounting/utils/current_account.py index 14df622..bbb574c 100644 --- a/src/accounting/utils/current_account.py +++ b/src/accounting/utils/current_account.py @@ -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"))