def apply_filters(self): self.entries = self.all_entries if self.filters['time']: try: begin_date, end_date = parse_date(self.filters['time']) self.entries, _ = summarize.clamp_opt(self.entries, begin_date, end_date, self.options) except TypeError: raise FilterException('Failed to parse date string: {}'.format(self.filters['time'])) if self.filters['tag']: self.entries = [entry for entry in self.entries if isinstance(entry, Transaction) and entry.tags and (entry.tags & set(self.filters['tag']))] if self.filters['payee']: self.entries = [entry for entry in self.entries if (isinstance(entry, Transaction) and entry.payee and (entry.payee in self.filters['payee'])) or (isinstance(entry, Transaction) and not entry.payee and ('' in self.filters['payee']))] if self.filters['account']: self.entries = [entry for entry in self.entries if isinstance(entry, Transaction) and any(has_component(posting.account, self.filters['account']) for posting in entry.postings)] self.root_account = realization.realize(self.entries, self.account_types) self.all_accounts = self._account_components() self.all_accounts_leaf_only = self._account_components(leaf_only=True) self.closing_entries = summarize.cap_opt(self.entries, self.options) self.closing_real_accounts = realization.realize(self.closing_entries, self.account_types)
def _initialize(self, options_map): """Compute the list of filtered entries and realization trees.""" # Get the filtered list of entries. self.entries, self.begin_index, self.price_date = self.apply_filter( self.all_entries, options_map) # Compute the list of entries for the opening balances sheet. self.opening_entries = (self.entries[:self.begin_index] if self.begin_index is not None else []) # Compute the list of entries that includes transfer entries of the # income/expenses amounts to the balance sheet's equity (as "net # income"). This is used to render the end-period balance sheet, with # the current period's net income, closing the period. self.closing_entries = summarize.cap_opt(self.entries, options_map) # Realize the three sets of entries. account_types = options.get_account_types(options_map) with misc_utils.log_time('realize_opening', logging.info): self.opening_real_accounts = realization.realize(self.opening_entries, account_types) with misc_utils.log_time('realize', logging.info): self.real_accounts = realization.realize(self.entries, account_types) with misc_utils.log_time('realize_closing', logging.info): self.closing_real_accounts = realization.realize(self.closing_entries, account_types) assert self.real_accounts is not None assert self.closing_real_accounts is not None
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 apply_filters(self): self.entries = self.all_entries if self.filters['time']: try: begin_date, end_date = parse_date(self.filters['time']) self.entries, _ = summarize.clamp_opt(self.entries, begin_date, end_date, self.options) except TypeError: raise FilterException('Failed to parse date string: {}'.format( self.filters['time'])) if self.filters['tag']: self.entries = [ entry for entry in self.entries if isinstance(entry, Transaction) and entry.tags and ( entry.tags & set(self.filters['tag'])) ] if self.filters['payee']: self.entries = [ entry for entry in self.entries if (isinstance(entry, Transaction) and entry.payee and (entry.payee in self.filters['payee'])) or ( isinstance(entry, Transaction) and not entry.payee and ('' in self.filters['payee'])) ] if self.filters['account']: self.entries = [ entry for entry in self.entries if isinstance(entry, Transaction) and any( has_component(posting.account, self.filters['account']) for posting in entry.postings) ] self.root_account = realization.realize(self.entries, self.account_types) self.all_accounts = self._account_components() self.all_accounts_leaf_only = self._account_components(leaf_only=True) self.closing_entries = summarize.cap_opt(self.entries, self.options) self.closing_real_accounts = realization.realize( self.closing_entries, self.account_types)
def root_account_closed(self): """A root account where closing entries have been generated.""" closing_entries = summarize.cap_opt(self.entries, self.options) return realization.realize(closing_entries)
def closing_balances(self, account_name): closing_entries = summarize.cap_opt(self.entries, self.options) return [serialize_real_account(self._real_account(account_name, closing_entries))]
def closing_balances(self, account_name): closing_entries = summarize.cap_opt(self.entries, self.options) return self._table_tree(self._real_account(account_name, closing_entries))
def closing_balances(self, account_name): closing_entries = summarize.cap_opt(self.entries, self.options) return realization.get_or_create(realization.realize(closing_entries), account_name)