Changeset - c88c5ef3b05d
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-06-04 01:24:47
brettcsmith@brettcsmith.org
accruals: AccrualPostings only reports inconsistent cost per currency.

Of course if an accrual has multiple currencies, it'll probably have
different costs, and that's fine.
3 files changed with 15 insertions and 35 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/accrual.py
Show inline comments
...
 
@@ -146,3 +146,2 @@ class AccrualPostings(core.RelatedPostings):
 
        'contract': _meta_getter('contract'),
 
        'cost': operator.attrgetter('cost'),
 
        'entity': _meta_getter('entity'),
...
 
@@ -159,4 +158,2 @@ class AccrualPostings(core.RelatedPostings):
 
        'contracts',
 
        'cost',
 
        'costs',
 
        'entity',
...
 
@@ -228,2 +225,13 @@ class AccrualPostings(core.RelatedPostings):
 
                    yield Error(post.meta, errmsg, post.meta.txn)
 
        costs = collections.defaultdict(set)
 
        for post in self:
 
            costs[post.units.currency].add(post.cost)
 
        for code, currency_costs in costs.items():
 
            if len(currency_costs) > 1:
 
                for post in self:
 
                    if post.units.currency == code:
 
                        errmsg = 'inconsistent cost for invoice {}: {}'.format(
 
                            self.invoice or "<none>", post.cost,
 
                        )
 
                        yield Error(post.meta, errmsg, post.meta.txn)
 

	
tests/books/accruals.beancount
Show inline comments
...
 
@@ -43,4 +43,4 @@
 
  approval: "rt:505/5040"
 
  Income:Donations  -1000.00 USD
 
  Assets:Receivable:Accounts  1000.00 USD
 
  Income:Donations  -2,500 EUR {1.100 USD}
 
  Assets:Receivable:Accounts  2,500 EUR {1.100 USD}
 

	
...
 
@@ -62,4 +62,4 @@
 
  invoice: "rt:505/5050"
 
  Assets:Receivable:Accounts  -1000.00 USD
 
  Assets:Checking  1000.00 USD
 
  Assets:Receivable:Accounts  -2,750.00 USD
 
  Assets:Checking  2,750.00 USD
 
  receipt: "DonorAWire.pdf"
tests/test_reports_accrual.py
Show inline comments
...
 
@@ -214,16 +214,2 @@ def test_accrual_postings_consistent_account(acct_name):
 

	
 
@pytest.mark.parametrize('cost', [
 
    testutil.Cost('1.2', 'USD'),
 
    None,
 
])
 
def test_accrual_postings_consistent_cost(cost):
 
    meta = {'invoice': 'FXinvoice.pdf'}
 
    txn = testutil.Transaction(postings=[
 
        (ACCOUNTS[0], 60, 'EUR', cost, meta),
 
        (ACCOUNTS[0], 30, 'EUR', cost, meta),
 
    ])
 
    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 
    assert related.cost == cost
 
    assert related.costs == {cost}
 

	
 
@pytest.mark.parametrize('meta_key,acct_name', testutil.combine_values(
...
 
@@ -257,16 +243,2 @@ def test_accrual_postings_inconsistent_account():
 

	
 
def test_accrual_postings_inconsistent_cost():
 
    meta = {'invoice': 'FXinvoice.pdf'}
 
    costs = {
 
        testutil.Cost('1.1', 'USD'),
 
        testutil.Cost('1.2', 'USD'),
 
    }
 
    txn = testutil.Transaction(postings=[
 
        (ACCOUNTS[0], 10, 'EUR', cost, meta)
 
        for cost in costs
 
    ])
 
    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 
    assert related.cost is related.INCONSISTENT
 
    assert related.costs == costs
 

	
 
@pytest.mark.parametrize('meta_key,acct_name', testutil.combine_values(
0 comments (0 inline, 0 general)