def hierarchy(self, account_name, begin=None, end=None): """An account tree.""" if begin: tree = Tree(iter_entry_dates(self.ledger.entries, begin, end)) else: tree = self.ledger.root_tree return tree.get(account_name).serialise(end)
def hierarchy(self, account_name, begin=None, end=None): """An account tree.""" if begin: tree = Tree(iter_entry_dates(self.ledger.entries, begin, end)) else: tree = self.ledger.root_tree return _serialize_account_node(tree.get(account_name), end)
def hierarchy(self, account_name, begin=None, end=None): """An account tree.""" if begin: entries = iter_entry_dates(self.ledger.entries, begin, end) tree = Tree(entries) else: tree = self.ledger.root_tree return _serialize_account_node(tree.get(account_name), end)
def hierarchy( self, account_name: str, begin: Optional[datetime.date] = None, end: Optional[datetime.date] = None, ): """An account tree.""" if begin is not None: tree = Tree(iter_entry_dates(self.ledger.entries, begin, end)) else: tree = self.ledger.root_tree return tree.get(account_name).serialise(end)
def hierarchy( self, account_name: str, conversion: str, begin: Optional[date] = None, end: Optional[date] = None, ) -> SerialisedTreeNode: """An account tree.""" if begin is not None and end is not None: tree = Tree(iter_entry_dates(self.ledger.entries, begin, end)) else: tree = self.ledger.root_tree return tree.get(account_name).serialise(conversion, self.ledger, end - ONE_DAY if end else None)
def filter( self, force: bool = False, account: str | None = None, filter: str | None = None, # pylint: disable=redefined-builtin time: str | None = None, ) -> None: """Set and apply (if necessary) filters.""" changed = self.filters.set(account=account, filter=filter, time=time) if not (changed or force): return self.entries = self.filters.apply(self.all_entries) self.root_account = realization.realize(self.entries, self.account_types) self.root_tree = Tree(self.entries) self._date_first, self._date_last = get_min_max_dates( self.entries, (Transaction, Price)) if self._date_last: self._date_last = self._date_last + datetime.timedelta(1) if self.filters.time: self._date_first = self.filters.time.begin_date self._date_last = self.filters.time.end_date
def test_tree_cap(example_ledger): closing_entries = summarize.cap_opt(example_ledger.entries, example_ledger.options) real_account = realization.realize(closing_entries) tree = Tree(example_ledger.entries) tree.cap(example_ledger.options, 'Unrealized') for account in realization.iter_children(real_account): name = account.account node = tree[name] if not name: continue if name.startswith('Expenses') or name.startswith('Income'): continue _compare_inv_and_counter(account.balance, node.balance)
def hierarchy( self, filtered: FilteredLedger, account_name: str, conversion: str, begin: date | None = None, end: date | None = None, ) -> SerialisedTreeNode: """An account tree.""" if begin is not None and end is not None: tree = Tree(iter_entry_dates(filtered.entries, begin, end)) else: tree = filtered.root_tree return tree.get(account_name).serialise(conversion, self.ledger.price_map, end - ONE_DAY if end else None)
def filter(self, force=False, **kwargs): """Set and apply (if necessary) filters.""" changed = False for filter_name, value in kwargs.items(): if self._filters[filter_name].set(value): changed = True if not (changed or force): return self.entries = self.all_entries for filter_class in self._filters.values(): self.entries = filter_class.apply(self.entries) self.root_account = realization.realize(self.entries, self.account_types) self.root_tree = Tree(self.entries) self._date_first, self._date_last = getters.get_min_max_dates( self.entries, (Transaction)) if self._date_last: self._date_last = self._date_last + datetime.timedelta(1) if self._filters["time"]: self._date_first = self._filters["time"].begin_date self._date_last = self._filters["time"].end_date
def test_tree_from_entries(example_ledger): tree = Tree(example_ledger.entries) real_account = realization.realize(example_ledger.entries) for account in realization.iter_children(real_account): name = account.account node = tree[name] _compare_inv_and_counter(account.balance, node.balance) _compare_inv_and_counter(realization.compute_balance(account), node.balance_children)
def portfolio_accounts(self, begin=None, end=None): """An account tree based on matching regex patterns.""" if begin: tree = Tree(iter_entry_dates(self.ledger.entries, begin, end)) else: tree = self.ledger.root_tree portfolios = [] for option in self.config: opt_key = option[0] if opt_key == "account_name_pattern": portfolio = self._account_name_pattern(tree, end, option[1]) elif opt_key == "account_open_metadata_pattern": portfolio = self._account_metadata_pattern( tree, end, option[1][0], option[1][1]) else: raise FavaAPIException("Portfolio List: Invalid option.") portfolios.append(portfolio) return portfolios
def portfolio_accounts(self, begin=None, end=None): """An account tree based on matching regex patterns.""" portfolios = [] try: self.load_report() if begin: tree = Tree(iter_entry_dates(self.ledger.entries, begin, end)) else: tree = self.ledger.root_tree for option in self.config: opt_key = option[0] if opt_key == "account_name_pattern": portfolio = self._account_name_pattern(tree, end, option[1]) elif opt_key == "account_open_metadata_pattern": portfolio = self._account_metadata_pattern( tree, end, option[1][0], option[1][1] ) else: exception = FavaAPIException("Classy Portfolio: Invalid option.") raise (exception) portfolio = ( portfolio[0], # title portfolio[1], # subtitle ( insert_rowspans(portfolio[2][0], portfolio[2][1], True), portfolio[2][1], ), # portfolio data ) portfolios.append(portfolio) except Exception as exc: traceback.print_exc(file=sys.stdout) return portfolios
def __init__( self, ledger: FavaLedger, account: str | None = None, filter: str | None = None, # pylint: disable=redefined-builtin time: str | None = None, ): self.ledger = ledger self.filters = Filters(ledger.options, ledger.fava_options) self.filters.set(account=account, filter=filter, time=time) self.entries = self.filters.apply(ledger.all_entries) self.root_account = realization.realize(self.entries, ledger.account_types) self.root_tree = Tree(self.entries) self._date_first, self._date_last = get_min_max_dates( self.entries, (Transaction, Price)) if self._date_last: self._date_last = self._date_last + datetime.timedelta(1) if self.filters.time: self._date_first = self.filters.time.begin_date self._date_last = self.filters.time.end_date
def root_tree(self) -> Any: """Root tree.""" return Tree(self.entries)
def root_tree_closed(self) -> Tree: """A root tree for the balance sheet.""" tree = Tree(self.entries) tree.cap(self.ledger.options, self.ledger.fava_options.unrealized) return tree
def test_tree(): tree = Tree() assert len(tree) == 1 tree.get('account:name:a:b:c') assert len(tree) == 1 node = tree.get('account:name:a:b:c', insert=True) assert len(tree) == 6 tree.get('account:name', insert=True) assert len(tree) == 6 assert node is tree.get('account:name:a:b:c', insert=True) assert list(tree.ancestors('account:name:a:b:c')) == [ tree.get('account:name:a:b'), tree.get('account:name:a'), tree.get('account:name'), tree.get('account'), tree.get(''), ] assert len(list(tree.ancestors('not:account:name:a:b:c'))) == 6
def test_tree(): tree = Tree() assert len(tree) == 1 tree.get("account:name:a:b:c") assert len(tree) == 1 node = tree.get("account:name:a:b:c", insert=True) assert len(tree) == 6 tree.get("account:name", insert=True) assert len(tree) == 6 assert node is tree.get("account:name:a:b:c", insert=True) assert list(tree.ancestors("account:name:a:b:c")) == [ tree.get("account:name:a:b"), tree.get("account:name:a"), tree.get("account:name"), tree.get("account"), tree.get(""), ] assert len(list(tree.ancestors("not:account:name:a:b:c"))) == 6
def root_tree_closed(self): """A root tree for the balance sheet.""" tree = Tree(self.entries) tree.cap(self.options, self.fava_options["unrealized"]) return tree
def root_tree_closed(self): """A root tree for the balance sheet.""" tree = Tree(self.entries) tree.cap(self.options, self.fava_options['unrealized']) return tree