Added the "sql_condition" method to the CurrentAccount data model to simplify the queries.
This commit is contained in:
parent
7e90ec5a8f
commit
0ad2ac53dd
@ -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(
|
||||
|
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user