Revised the __set_data method of the trial balance and the __query_balances of the income statement for consistency.
This commit is contained in:
parent
ed7a8ac0fd
commit
8abe20dba5
@ -269,16 +269,15 @@ class IncomeStatement(BaseReport):
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, -JournalEntry.amount),
|
||||
else_=JournalEntry.amount)).label("balance")
|
||||
select_balance: sa.Select \
|
||||
= sa.select(JournalEntry.account_id, balance_func)\
|
||||
select_balances: sa.Select = sa.select(Account.id, balance_func)\
|
||||
.join(Transaction).join(Account)\
|
||||
.filter(*conditions)\
|
||||
.group_by(JournalEntry.account_id)\
|
||||
.group_by(Account.id)\
|
||||
.order_by(Account.base_code, Account.no)
|
||||
balances: list[sa.Row] = db.session.execute(select_balance).all()
|
||||
balances: list[sa.Row] = db.session.execute(select_balances).all()
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query
|
||||
.filter(Account.id.in_([x.account_id for x in balances])).all()}
|
||||
.filter(Account.id.in_([x.id for x in balances])).all()}
|
||||
|
||||
def get_url(account: Account) -> str:
|
||||
"""Returns the ledger URL of an account.
|
||||
@ -293,9 +292,9 @@ class IncomeStatement(BaseReport):
|
||||
currency=self.__currency, account=account,
|
||||
period=self.__period)
|
||||
|
||||
return [ReportAccount(account=accounts[x.account_id],
|
||||
return [ReportAccount(account=accounts[x.id],
|
||||
amount=x.balance,
|
||||
url=get_url(accounts[x.account_id]))
|
||||
url=get_url(accounts[x.id]))
|
||||
for x in balances]
|
||||
|
||||
def csv(self) -> Response:
|
||||
|
@ -191,11 +191,10 @@ class TrialBalance(BaseReport):
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount)).label("balance")
|
||||
select_balances: sa.Select \
|
||||
= sa.select(Account.id, balance_func)\
|
||||
select_balances: sa.Select = sa.select(Account.id, balance_func)\
|
||||
.join(Transaction).join(Account)\
|
||||
.filter(*conditions)\
|
||||
.group_by(JournalEntry.account_id)\
|
||||
.group_by(Account.id)\
|
||||
.order_by(Account.base_code, Account.no)
|
||||
balances: list[sa.Row] = db.session.execute(select_balances).all()
|
||||
accounts: dict[int, Account] \
|
||||
|
Loading…
Reference in New Issue
Block a user