Changeset - 9699f4e52766
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-25 17:52:37
brettcsmith@brettcsmith.org
income_type: Set a default for TrademarkSales. RT#8869.
2 files changed with 2 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_income_type.py
Show inline comments
...
 
@@ -27,26 +27,27 @@ class MetaIncomeType(core._NormalizePostingMetadataHook):
 
        'Donations',
 
        'Payable-Derecognition',
 
        'RBI',
 
        'UBTI',
 
    })
 
    DEFAULT_VALUES = {
 
        'Income:Conferences:Registrations': 'RBI',
 
        'Income:Conferences:Sponsorship': 'RBI',
 
        'Income:Donations': 'Donations',
 
        'Income:Honoraria': 'RBI',
 
        'Income:Interest': 'RBI',
 
        'Income:Interest:Dividend': 'RBI',
 
        'Income:Royalties': 'RBI',
 
        'Income:Sales': 'RBI',
 
        'Income:SoftwareDevelopment': 'RBI',
 
        'Income:TrademarkLicensing': 'RBI',
 
        'Income:TrademarkSales': 'RBI',
 
    }
 

	
 
    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
 
        return post.account.is_under('Income') is not None
 

	
 
    def _default_value(self, txn: Transaction, post: data.Posting) -> MetaValueEnum:
 
        try:
 
            return self.DEFAULT_VALUES[post.account]
 
        except KeyError:
 
            raise errormod.InvalidMetadataError(txn, self.METADATA_KEY, None, post) from None
tests/test_meta_income_type.py
Show inline comments
...
 
@@ -98,32 +98,33 @@ def test_non_income_accounts_skipped(hook, account):
 
    ])
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, meta)
 

	
 
@pytest.mark.parametrize('account,set_value', [
 
    ('Income:Conferences:Registrations', 'RBI'),
 
    ('Income:Conferences:Sponsorship', 'RBI'),
 
    ('Income:Donations', 'Donations'),
 
    ('Income:Honoraria', 'RBI'),
 
    ('Income:Interest', 'RBI'),
 
    ('Income:Interest:Dividend', 'RBI'),
 
    ('Income:Royalties', 'RBI'),
 
    ('Income:Sales', 'RBI'),
 
    ('Income:SoftwareDevelopment', 'RBI'),
 
    ('Income:TrademarkLicensing', 'RBI'),
 
    ('Income:TrademarkSales', 'RBI'),
 
])
 
def test_default_values(hook, account, set_value):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', 25),
 
        (account, -25),
 
    ])
 
    errors = list(hook.run(txn))
 
    assert not errors
 
    testutil.check_post_meta(txn, None, {TEST_KEY: set_value})
 

	
 
@pytest.mark.parametrize('account', [
 
    'Income:Other',
 
])
 
def test_no_default_value(hook, account):
 
    txn = testutil.Transaction(postings=[
 
        ('Assets:Cash', 25),
0 comments (0 inline, 0 general)