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
...
 
@@ -74,2 +74,4 @@ class MetaEntity(core.TransactionHook):
 
            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):
tests/test_meta_entity.py
Show inline comments
...
 
@@ -120,3 +120,3 @@ def test_invalid_values_on_postings(hook, src_value):
 
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),
...
 
@@ -125,2 +125,4 @@ def test_valid_values_on_transactions(hook, src_value):
 
    assert not any(hook.run(txn))
 
    # Make sure payee doesn't overwrite metadata. See payee test below.
 
    assert txn.meta[TEST_KEY] == src_value
 

	
...
 
@@ -153,2 +155,5 @@ def test_valid_values_on_payee(hook, src_value):
 
    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
 

	
0 comments (0 inline, 0 general)