balance_sheet: Fix unwanted hierarchy traversal in Trial Balances.
The balances reported on the trial balances sheet included an account's subaccounts. e.g., the balance for Expenses:A would include the balance for Expenses:A:B. We don't want that traversal for this report, so inhibit it and report only exact account balances.
This commit is contained in:
parent
639a41b782
commit
fe52fe50a1
1 changed files with 21 additions and 4 deletions
|
@ -148,12 +148,25 @@ class Balances:
|
||||||
period: int=Period.ANY,
|
period: int=Period.ANY,
|
||||||
fund: int=Fund.ANY,
|
fund: int=Fund.ANY,
|
||||||
post_type: Optional[str]=None,
|
post_type: Optional[str]=None,
|
||||||
|
*,
|
||||||
|
account_exact: bool=False,
|
||||||
) -> core.Balance:
|
) -> core.Balance:
|
||||||
if isinstance(account, str):
|
if isinstance(account, str):
|
||||||
account = (account,)
|
account = (account,)
|
||||||
|
acct_pred: Callable[[data.Account], bool]
|
||||||
|
if account is None:
|
||||||
|
acct_pred = lambda acct: True
|
||||||
|
elif account_exact:
|
||||||
|
# At this point, between this isinstance() above and the earlier
|
||||||
|
# `account is None` check, we've collapsed the type of `account` to
|
||||||
|
# `Collection[str]`. Unfortunately the logic is too involved for
|
||||||
|
# mypy to follow, so ignore the type problem.
|
||||||
|
acct_pred = lambda acct: acct in account # type:ignore[operator]
|
||||||
|
else:
|
||||||
|
acct_pred = lambda acct: acct.is_under(*account) is not None # type:ignore[misc]
|
||||||
retval = core.MutableBalance()
|
retval = core.MutableBalance()
|
||||||
for key, balance in self.balances.items():
|
for key, balance in self.balances.items():
|
||||||
if not (account is None or key.account.is_under(*account)):
|
if not acct_pred(key.account):
|
||||||
pass
|
pass
|
||||||
elif not (classification is None
|
elif not (classification is None
|
||||||
or key.classification.is_under(classification)):
|
or key.classification.is_under(classification)):
|
||||||
|
@ -599,10 +612,14 @@ class Report(core.BaseODS[Sequence[None], None]):
|
||||||
want_balance = acct_root not in EQUITY_ACCOUNTS
|
want_balance = acct_root not in EQUITY_ACCOUNTS
|
||||||
self.add_row()
|
self.add_row()
|
||||||
for account in self.balances.iter_accounts(acct_root):
|
for account in self.balances.iter_accounts(acct_root):
|
||||||
period_bal = self.balances.total(account=account, period=Period.PERIOD)
|
period_bal = self.balances.total(
|
||||||
prior_bal = self.balances.total(account=account, period=Period.PRIOR)
|
account=account, period=Period.PERIOD, account_exact=True,
|
||||||
|
)
|
||||||
|
prior_bal = self.balances.total(
|
||||||
|
account=account, period=Period.PRIOR, account_exact=True,
|
||||||
|
)
|
||||||
if want_balance:
|
if want_balance:
|
||||||
close_bal = self.balances.total(account=account)
|
close_bal = self.balances.total(account=account, account_exact=True)
|
||||||
close_cell = self.balance_cell(norm_func(close_bal))
|
close_cell = self.balance_cell(norm_func(close_bal))
|
||||||
open_cell = self.balance_cell(norm_func(close_bal - period_bal))
|
open_cell = self.balance_cell(norm_func(close_bal - period_bal))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue