accrual: Add AccrualPostings.rt_id property.
This is like the existing attributes, but it only supports the outgoings report, so don't build it at __init__ time.
This commit is contained in:
		
							parent
							
								
									52fc0d1b5f
								
							
						
					
					
						commit
						8d7a2b1eea
					
				
					 2 changed files with 28 additions and 0 deletions
				
			
		| 
						 | 
					@ -258,6 +258,10 @@ class AccrualPostings(core.RelatedPostings):
 | 
				
			||||||
            empty = True
 | 
					            empty = True
 | 
				
			||||||
        return self if empty else self[start_index + 1:]
 | 
					        return self if empty else self[start_index + 1:]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def rt_id(self) -> Union[str, None, Sentinel]:
 | 
				
			||||||
 | 
					        return self._single_item(self.first_meta_links('rt-id', None))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BaseReport:
 | 
					class BaseReport:
 | 
				
			||||||
    def __init__(self, out_file: TextIO) -> None:
 | 
					    def __init__(self, out_file: TextIO) -> None:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -309,6 +309,30 @@ def test_accrual_postings_inconsistent_account():
 | 
				
			||||||
    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 | 
					    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 | 
				
			||||||
    assert related.account is related.INCONSISTENT
 | 
					    assert related.account is related.INCONSISTENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_accrual_postings_rt_id():
 | 
				
			||||||
 | 
					    txn = testutil.Transaction(postings=[
 | 
				
			||||||
 | 
					        (ACCOUNTS[0], 10, {'rt-id': 'rt:90'}),
 | 
				
			||||||
 | 
					        (ACCOUNTS[0], 10, {'rt-id': 'rt:90 rt:92'}),
 | 
				
			||||||
 | 
					        (ACCOUNTS[0], 10, {'rt-id': 'rt:90 rt:94 rt:92'}),
 | 
				
			||||||
 | 
					    ])
 | 
				
			||||||
 | 
					    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 | 
				
			||||||
 | 
					    assert related.rt_id == 'rt:90'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_accrual_postings_rt_id_inconsistent():
 | 
				
			||||||
 | 
					    txn = testutil.Transaction(postings=[
 | 
				
			||||||
 | 
					        (ACCOUNTS[0], 10, {'rt-id': 'rt:96'}),
 | 
				
			||||||
 | 
					        (ACCOUNTS[0], 10, {'rt-id': 'rt:98 rt:96'}),
 | 
				
			||||||
 | 
					    ])
 | 
				
			||||||
 | 
					    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 | 
				
			||||||
 | 
					    assert related.rt_id is related.INCONSISTENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_accrual_postings_rt_id_none():
 | 
				
			||||||
 | 
					    txn = testutil.Transaction(postings=[
 | 
				
			||||||
 | 
					        (ACCOUNTS[0], 10),
 | 
				
			||||||
 | 
					    ])
 | 
				
			||||||
 | 
					    related = accrual.AccrualPostings(data.Posting.from_txn(txn))
 | 
				
			||||||
 | 
					    assert related.rt_id is None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize('acct_name,invoice,day', testutil.combine_values(
 | 
					@pytest.mark.parametrize('acct_name,invoice,day', testutil.combine_values(
 | 
				
			||||||
    ACCOUNTS,
 | 
					    ACCOUNTS,
 | 
				
			||||||
    ['FIXME', '', None, *testutil.NON_STRING_METADATA_VALUES],
 | 
					    ['FIXME', '', None, *testutil.NON_STRING_METADATA_VALUES],
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue