def _include_entry(self, entry): if isinstance(entry, Transaction): return any(account.has_component(posting.account, self.value) for posting in entry.postings) else: return (hasattr(entry, 'account') and account.has_component(entry.account, self.value))
def test_account_filter(example_ledger): account_filter = AccountFilter( example_ledger.options, example_ledger.fava_options ) account_filter.set("Assets") filtered_entries = account_filter.apply(example_ledger.all_entries) assert len(filtered_entries) == 541 assert all( map( lambda x: hasattr(x, "account") and account.has_component(x.account, "Assets") or any( map( lambda p: account.has_component(p.account, "Assets"), x.postings, ) ), filtered_entries, ) ) account_filter.set(".*US:State") filtered_entries = account_filter.apply(example_ledger.all_entries) assert len(filtered_entries) == 67
def _include_entry(self, entry): if isinstance(entry, Transaction): return any( account.has_component(posting.account, self.value) for posting in entry.postings) else: return (hasattr(entry, 'account') and account.has_component(entry.account, self.value))
def test_account_filter(example_api): account_filter = AccountFilter() account_filter.set('Assets') filtered_entries = account_filter.apply( example_api.all_entries, example_api.options) assert len(filtered_entries) == 537 assert all(map( lambda x: hasattr(x, 'account') and account.has_component(x.account, 'Assets') or any(map( lambda p: account.has_component(p.account, 'Assets'), x.postings)), filtered_entries))
def test_account_filter(example_api): account_filter = AccountFilter() account_filter.set('Assets') filtered_entries = account_filter.apply(example_api.all_entries, example_api.options) assert len(filtered_entries) == 537 assert all( map( lambda x: hasattr(x, 'account') and account.has_component( x.account, 'Assets') or any( map(lambda p: account.has_component(p.account, 'Assets'), x .postings)), filtered_entries))
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 test_account_filter(example_ledger): account_filter = AccountFilter(example_ledger.options, example_ledger.fava_options) account_filter.set('Assets') filtered_entries = account_filter.apply(example_ledger.all_entries) assert len(filtered_entries) == 541 assert all(map( lambda x: hasattr(x, 'account') and account.has_component(x.account, 'Assets') or any(map( lambda p: account.has_component(p.account, 'Assets'), x.postings)), filtered_entries)) account_filter.set('.*US:State') filtered_entries = account_filter.apply(example_ledger.all_entries) assert len(filtered_entries) == 67
def _include_entry(self, entry: Directive) -> bool: if self.value is None: return False return any( account.has_component(name, self.value) or self.match(name) for name in get_entry_accounts(entry) )
def test_has_component(self): self.assertTrue(account.has_component('Liabilities:US:Credit-Card', 'US')) self.assertFalse(account.has_component('Liabilities:US:Credit-Card', 'CA')) self.assertTrue(account.has_component('Liabilities:US:Credit-Card', 'Credit-Card')) self.assertTrue(account.has_component('Liabilities:US:Credit-Card', 'Liabilities')) self.assertFalse(account.has_component('Liabilities:US:Credit-Card', 'Credit')) self.assertFalse(account.has_component('Liabilities:US:Credit-Card', 'Card'))
def has_entry_account_component(entry, component): """Return true if one of the entry's postings has an account component. Args: entry: A Transaction entry. component: A string, a component of an account name. For instance, 'Food' in 'Expenses:Food:Restaurant'. All components are considered. Returns: A boolean, true if the component is in the account. Note that a component name must be whole, that is 'NY' is not in Expenses:Taxes:StateNY'. """ return (isinstance(entry, Transaction) and any( has_component(posting.account, component) for posting in entry.postings))
def test_account_filter(example_ledger: FavaLedger) -> None: account_filter = AccountFilter(example_ledger.options, example_ledger.fava_options) account_filter.set("Assets") filtered_entries = account_filter.apply(example_ledger.all_entries) assert len(filtered_entries) == 541 for entry in filtered_entries: assert any( has_component(a, "Assets") for a in get_entry_accounts(entry)) account_filter.set(".*US:State") filtered_entries = account_filter.apply(example_ledger.all_entries) assert len(filtered_entries) == 67
def open_dit_accounts(entries, dit_component): """ Minimally adapted from beancount.plugins.auto_accounts. """ opened_accounts = {entry.account for entry in entries if isinstance(entry, data.Open)} new_entries = [] accounts_first, _ = getters.get_accounts_use_map(entries) for index, (account, date_first_used) in enumerate(sorted(accounts_first.items())): if ((account not in opened_accounts) and has_component(account, dit_component)): meta = data.new_metadata(__name__, index) new_entry = data.Open(meta, date_first_used, account, None, None) new_entries.append(new_entry) return new_entries
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 open_dit_accounts(entries, dit_component): """ Minimally adapted from beancount.plugins.auto_accounts. """ opened_accounts = { entry.account for entry in entries if isinstance(entry, data.Open) } new_entries = [] accounts_first, _ = getters.get_accounts_use_map(entries) for index, (account, date_first_used) in enumerate(sorted(accounts_first.items())): if ((account not in opened_accounts) and has_component(account, dit_component)): meta = data.new_metadata(__name__, index) new_entry = data.Open(meta, date_first_used, account, None, None) new_entries.append(new_entry) return new_entries
def split_entries(entries, dit_component, ignored_tag): dits, unchanged_entries, errors = [], [], [] for entry in entries: if (isinstance(entry, data.Transaction) and not (entry.tags and ignored_tag in entry.tags)): dit_postings = [posting for posting in entry.postings if has_component(posting.account, dit_component)] num_dit_postings = len(dit_postings) else: num_dit_postings = 0 if num_dit_postings == 0: unchanged_entries.append(entry) else: dits.append(data.TxnPosting(entry, dit_postings[0])) if num_dit_postings > 1: errors.append(DITError( entry.meta, "(deposit_in_transit) Found entry with multiple postings to DIT accounts; " "only processing posting to {} account".format( dit_postings[0].account), entry)) return dits, unchanged_entries, errors
def split_entries(entries, dit_component, ignored_tag): dits, unchanged_entries, errors = [], [], [] for entry in entries: if (isinstance(entry, data.Transaction) and not (entry.tags and ignored_tag in entry.tags)): dit_postings = [ posting for posting in entry.postings if has_component(posting.account, dit_component) ] num_dit_postings = len(dit_postings) else: num_dit_postings = 0 if num_dit_postings == 0: unchanged_entries.append(entry) else: dits.append(data.TxnPosting(entry, dit_postings[0])) if num_dit_postings > 1: errors.append( DITError( entry.meta, "(deposit_in_transit) Found entry with multiple postings to DIT accounts; " "only processing posting to {} account".format( dit_postings[0].account), entry)) return dits, unchanged_entries, errors
def _include_entry(self, entry): return isinstance(entry, Transaction) and \ any(has_component(posting.account, self.value) for posting in entry.postings)
def _account_predicate(self, name): return account.has_component(name, self.value) or self.match(name)
def _match_account(name, filter): if filter == '.*' and not re.match(filter, name): print(name) return (account.has_component(name, filter) or re.match(filter, name))
def _match_account(name, search): return (account.has_component(name, search) or _match(search, name))