Changeset - 89aaae821b30
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-03-18 20:25:37
brettcsmith@brettcsmith.org
data.Account: Exclude PrepaidVacation from "real" assets.

Same rationale as PrepaidExpenses.
2 files changed with 2 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/data.py
Show inline comments
...
 
@@ -18,48 +18,49 @@ import collections.abc
 

	
 
from beancount.core import account as bc_account
 

	
 
from typing import (
 
    Iterable,
 
    Iterator,
 
    MutableMapping,
 
    Optional,
 
)
 

	
 
from .beancount_types import (
 
    MetaKey,
 
    MetaValue,
 
    Posting as BasePosting,
 
    Transaction,
 
)
 

	
 
class Account(str):
 
    SEP = bc_account.sep
 

	
 
    def is_real_asset(self) -> bool:
 
        return (
 
            self.is_under('Assets:')
 
            and not self.is_under('Assets:PrepaidExpenses')
 
            and not self.is_under('Assets:PrepaidVacation')
 
        )
 

	
 
    def is_under(self, acct_s: str) -> bool:
 
        return self.startswith(acct_s) and (
 
            acct_s.endswith(self.SEP)
 
            or self == acct_s
 
            or self[len(acct_s)] == self.SEP
 
        )
 

	
 

	
 
class PostingMeta(collections.abc.MutableMapping):
 
    def __init__(self,
 
                 txn: Transaction,
 
                 index: int,
 
                 post: Optional[BasePosting]=None,
 
    ) -> None:
 
        if post is None:
 
            post = txn.postings[index]
 
        self.txn = txn
 
        self.index = index
 
        self.post = post
 

	
 
    def __iter__(self) -> Iterator[MetaKey]:
 
        keys: Iterable[MetaKey]
tests/test_data_account.py
Show inline comments
...
 
@@ -16,30 +16,31 @@
 

	
 
import pytest
 

	
 
from conservancy_beancount import data
 

	
 
@pytest.mark.parametrize('acct_name,under_arg,expected', [
 
    ('Expenses:Tax:Sales', 'Expenses:Tax:Sales:', False),
 
    ('Expenses:Tax:Sales', 'Expenses:Tax:Sales', True),
 
    ('Expenses:Tax:Sales', 'Expenses:Tax:', True),
 
    ('Expenses:Tax:Sales', 'Expenses:Tax', True),
 
    ('Expenses:Tax:Sales', 'Expenses:', True),
 
    ('Expenses:Tax:Sales', 'Expenses', True),
 
    ('Expenses:Tax:Sales', 'Accrued:', False),
 
    ('Expenses:Tax:Sales', 'Accrued', False),
 
])
 
def test_is_under(acct_name, under_arg, expected):
 
    assert data.Account(acct_name).is_under(under_arg) == expected
 

	
 
@pytest.mark.parametrize('acct_name,expected', [
 
    ('Accrued:AccountsPayable', False),
 
    ('Accrued:AccountsReceivable', False),
 
    ('Assets:Cash', True),
 
    ('Assets:Cash:EUR', True),
 
    ('Assets:PrepaidExpenses', False),
 
    ('Assets:PrepaidVacation', False),
 
    ('Assets:Bank:Checking', True),
 
    ('Expenses:General', False),
 
    ('Income:Donations', False),
 
])
 
def test_is_real_asset(acct_name, expected):
 
    assert data.Account(acct_name).is_real_asset() == expected
0 comments (0 inline, 0 general)