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
|
@property
|
||||||
def __account_condition(self) -> sa.BinaryExpression:
|
def __account_condition(self) -> sa.BinaryExpression:
|
||||||
if self.__account.code == CurrentAccount.CURRENT_AL_CODE:
|
if self.__account.code == CurrentAccount.CURRENT_AL_CODE:
|
||||||
return sa.or_(Account.base_code.startswith("11"),
|
return CurrentAccount.sql_condition()
|
||||||
Account.base_code.startswith("12"),
|
|
||||||
Account.base_code.startswith("21"),
|
|
||||||
Account.base_code.startswith("22"))
|
|
||||||
return Account.id == self.__account.id
|
return Account.id == self.__account.id
|
||||||
|
|
||||||
def __get_total(self) -> ReportLineItem | None:
|
def __get_total(self) -> ReportLineItem | None:
|
||||||
@ -352,10 +349,7 @@ class PageParams(BasePageParams):
|
|||||||
.join(Account)\
|
.join(Account)\
|
||||||
.filter(be(JournalEntryLineItem.currency_code
|
.filter(be(JournalEntryLineItem.currency_code
|
||||||
== self.currency.code),
|
== self.currency.code),
|
||||||
sa.or_(Account.base_code.startswith("11"),
|
CurrentAccount.sql_condition())\
|
||||||
Account.base_code.startswith("12"),
|
|
||||||
Account.base_code.startswith("21"),
|
|
||||||
Account.base_code.startswith("22")))\
|
|
||||||
.group_by(JournalEntryLineItem.account_id)
|
.group_by(JournalEntryLineItem.account_id)
|
||||||
options.extend([OptionLink(str(x),
|
options.extend([OptionLink(str(x),
|
||||||
income_expenses_url(
|
income_expenses_url(
|
||||||
|
@ -75,9 +75,19 @@ class CurrentAccount:
|
|||||||
accounts: list[cls] = [cls.current_assets_and_liabilities()]
|
accounts: list[cls] = [cls.current_assets_and_liabilities()]
|
||||||
accounts.extend([CurrentAccount(x)
|
accounts.extend([CurrentAccount(x)
|
||||||
for x in db.session.query(Account)
|
for x in db.session.query(Account)
|
||||||
.filter(sa.or_(Account.base_code.startswith("11"),
|
.filter(cls.sql_condition())
|
||||||
Account.base_code.startswith("12"),
|
|
||||||
Account.base_code.startswith("21"),
|
|
||||||
Account.base_code.startswith("22")))
|
|
||||||
.order_by(Account.base_code, Account.no)])
|
.order_by(Account.base_code, Account.no)])
|
||||||
return accounts
|
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