Changeset - fe52fe50a188
[Not reviewed]
0 1 0
Brett Smith - 4 years ago 2020-10-06 18:29:19
brettcsmith@brettcsmith.org
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.
1 file changed with 21 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/balance_sheet.py
Show inline comments
...
 
@@ -150,2 +150,4 @@ class Balances:
 
              post_type: Optional[str]=None,
 
              *,
 
              account_exact: bool=False,
 
    ) -> core.Balance:
...
 
@@ -153,5 +155,16 @@ class Balances:
 
            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()
 
        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
...
 
@@ -601,6 +614,10 @@ class Report(core.BaseODS[Sequence[None], None]):
 
            for account in self.balances.iter_accounts(acct_root):
 
                period_bal = self.balances.total(account=account, period=Period.PERIOD)
 
                prior_bal = self.balances.total(account=account, period=Period.PRIOR)
 
                period_bal = self.balances.total(
 
                    account=account, period=Period.PERIOD, account_exact=True,
 
                )
 
                prior_bal = self.balances.total(
 
                    account=account, period=Period.PRIOR, account_exact=True,
 
                )
 
                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))
0 comments (0 inline, 0 general)