Changeset - aa1f2ea35aed
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-08-18 05:28:37
brettcsmith@brettcsmith.org
balance_sheet: Balance.total() accepts multiple account names.

This simplifies the code to total all equity.
2 files changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/balance_sheet.py
Show inline comments
...
 
@@ -29,2 +29,3 @@ from typing import (
 
    Any,
 
    Collection,
 
    Dict,
...
 
@@ -40,2 +41,3 @@ from typing import (
 
    Tuple,
 
    Union,
 
)
...
 
@@ -129,3 +131,3 @@ class Balances:
 
    def total(self,
 
              account: Optional[str]=None,
 
              account: Union[None, str, Collection[str]]=None,
 
              classification: Optional[str]=None,
...
 
@@ -135,5 +137,7 @@ class Balances:
 
    ) -> core.Balance:
 
        if isinstance(account, str):
 
            account = (account,)
 
        retval = core.MutableBalance()
 
        for key, balance in self.balances.items():
 
            if not (account is None or key.account.is_under(account)):
 
            if not (account is None or key.account.is_under(*account)):
 
                pass
...
 
@@ -330,9 +334,5 @@ class Report(core.BaseODS[Sequence[None], None]):
 
            preposition = "Without" if fund is Fund.UNRESTRICTED else "With"
 
            period_bal = -sum(
 
                (self.balances.total(account=account, fund=fund)
 
                 for account in EQUITY_ACCOUNTS), core.MutableBalance(),
 
            )
 
            prior_bal = period_bal + sum(
 
                (self.balances.total(account=account, fund=fund, period=Period.PERIOD)
 
                 for account in EQUITY_ACCOUNTS), core.MutableBalance(),
 
            period_bal = -self.balances.total(account=EQUITY_ACCOUNTS, fund=fund)
 
            prior_bal = period_bal + self.balances.total(
 
                account=EQUITY_ACCOUNTS, fund=fund, period=Period.PERIOD,
 
            )
...
 
@@ -498,4 +498,3 @@ class Report(core.BaseODS[Sequence[None], None]):
 
        beginnings = [
 
            -sum((self.balances.total(account=account, **kwargs)
 
                  for account in EQUITY_ACCOUNTS), core.MutableBalance())
 
            -self.balances.total(account=EQUITY_ACCOUNTS, **kwargs)
 
            for kwargs in bal_kwargs
...
 
@@ -609,4 +608,3 @@ class Report(core.BaseODS[Sequence[None], None]):
 
        totals = [
 
            -sum((self.balances.total(account=account, **kwargs)
 
                  for account in EQUITY_ACCOUNTS), core.MutableBalance())
 
            -self.balances.total(account=EQUITY_ACCOUNTS, **kwargs)
 
            for kwargs in bal_kwargs
tests/test_reports_balance_sheet.py
Show inline comments
...
 
@@ -96,2 +96,4 @@ def income_expense_balances():
 
    ({'period': Period.PERIOD, 'fund': Fund.RESTRICTED, 'post_type': 'ΓΈ'}, None),
 
    ({'account': ('Income', 'Expenses')}, 30),
 
    ({'account': ('Income', 'Expenses'), 'fund': Fund.UNRESTRICTED}, 15),
 
])
0 comments (0 inline, 0 general)