Esempio n. 1
0
 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))
Esempio n. 2
0
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
Esempio n. 3
0
 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))
Esempio n. 5
0
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))
Esempio n. 6
0
    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)
Esempio n. 7
0
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
Esempio n. 8
0
 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)
     )
Esempio n. 9
0
 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'))
Esempio n. 10
0
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))
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
    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)
Esempio n. 14
0
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
Esempio n. 15
0
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
Esempio n. 16
0
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
Esempio n. 17
0
 def _include_entry(self, entry):
     return isinstance(entry, Transaction) and \
         any(has_component(posting.account, self.value)
             for posting in entry.postings)
Esempio n. 18
0
 def _account_predicate(self, name):
     return account.has_component(name, self.value) or self.match(name)
Esempio n. 19
0
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))
Esempio n. 20
0
def _match_account(name, search):
    return (account.has_component(name, search) or _match(search, name))
Esempio n. 21
0
 def _account_predicate(self, name):
     return account.has_component(name, self.value) or self.match(name)
Esempio n. 22
0
def _match_account(name, search):
    return (account.has_component(name, search) or
            _match(search, name))