Changeset - 8bc17dbf4a9a
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-09-10 20:06:43
brettcsmith@brettcsmith.org
meta_entity: Set metadata when entity comes from payee. RT#12525

This makes it easier to write bean-queries, since you don't have to check
two places for the "real" entity.
2 files changed with 8 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_entity.py
Show inline comments
...
 
@@ -72,6 +72,8 @@ class MetaEntity(core.TransactionHook):
 
        txn_entity, txn_entity_ok = self._check_entity(txn.meta, txn.payee)
 
        if txn_entity_ok is False:
 
            yield errormod.InvalidMetadataError(txn, self.METADATA_KEY, txn_entity)
 
        if txn_entity is txn.payee:
 
            txn.meta[self.METADATA_KEY] = txn.payee
 
        for post in data.Posting.from_txn(txn):
 
            if not post.account.is_under(
 
                    'Assets:Receivable',
tests/test_meta_entity.py
Show inline comments
...
 
@@ -118,11 +118,13 @@ def test_invalid_values_on_postings(hook, src_value):
 

	
 
@pytest.mark.parametrize('src_value', VALID_VALUES)
 
def test_valid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
    txn = testutil.Transaction(payee='Payee', **{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25),
 
    ])
 
    assert not any(hook.run(txn))
 
    # Make sure payee doesn't overwrite metadata. See payee test below.
 
    assert txn.meta[TEST_KEY] == src_value
 

	
 
@pytest.mark.parametrize('src_value', ANONYMOUS_VALUES)
 
def test_anonymous_values_on_transactions(hook, src_value):
...
 
@@ -151,6 +153,9 @@ def test_valid_values_on_payee(hook, src_value):
 
        ('Expenses:General', 25),
 
    ])
 
    assert not any(hook.run(txn))
 
    # In this case, we want the hook to set metadata to make it easier to
 
    # write bean-queries.
 
    assert txn.meta[TEST_KEY] == src_value
 

	
 
@pytest.mark.parametrize('src_value', ANONYMOUS_VALUES)
 
def test_anonymous_values_on_payee(hook, src_value):
0 comments (0 inline, 0 general)