meta_receipt: Applies to both credits and debits.
This commit is contained in:
		
							parent
							
								
									258099264e
								
							
						
					
					
						commit
						7cac21b780
					
				
					 2 changed files with 3 additions and 10 deletions
				
			
		| 
						 | 
					@ -26,13 +26,13 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
 | 
				
			||||||
    METADATA_KEY = 'receipt'
 | 
					    METADATA_KEY = 'receipt'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, config: configmod.Config) -> None:
 | 
					    def __init__(self, config: configmod.Config) -> None:
 | 
				
			||||||
        self.payment_threshold = -abs(config.payment_threshold())
 | 
					        self.payment_threshold = abs(config.payment_threshold())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
 | 
					    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
 | 
				
			||||||
        return bool(
 | 
					        return bool(
 | 
				
			||||||
            (post.account.is_real_asset() or post.account.is_under('Liabilities'))
 | 
					            (post.account.is_real_asset() or post.account.is_under('Liabilities'))
 | 
				
			||||||
            and post.units.number is not None
 | 
					            and post.units.number is not None
 | 
				
			||||||
            and post.units.number < self.payment_threshold
 | 
					            and abs(post.units.number) >= self.payment_threshold
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def post_run(self, txn: Transaction, post: data.Posting) -> errormod.Iter:
 | 
					    def post_run(self, txn: Transaction, post: data.Posting) -> errormod.Iter:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,7 +83,7 @@ NOT_REQUIRED_ACCOUNTS = itertools.cycle([
 | 
				
			||||||
])
 | 
					])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def check(hook, test_acct, other_acct, expected, *,
 | 
					def check(hook, test_acct, other_acct, expected, *,
 | 
				
			||||||
          txn_meta={}, post_meta={}, check_type=PostType.DEBIT, min_amt=0):
 | 
					          txn_meta={}, post_meta={}, check_type=PostType.BOTH, min_amt=0):
 | 
				
			||||||
    check_type &= test_acct.required_types
 | 
					    check_type &= test_acct.required_types
 | 
				
			||||||
    assert check_type, "tried to test a non-applicable account"
 | 
					    assert check_type, "tried to test a non-applicable account"
 | 
				
			||||||
    if check_type == PostType.BOTH:
 | 
					    if check_type == PostType.BOTH:
 | 
				
			||||||
| 
						 | 
					@ -233,10 +233,3 @@ def test_bad_type_fallback_on_txn(hook, test_acct, other_acct, value):
 | 
				
			||||||
def test_fallback_not_accepted_on_other_accounts(hook, test_acct, other_acct, key, value):
 | 
					def test_fallback_not_accepted_on_other_accounts(hook, test_acct, other_acct, key, value):
 | 
				
			||||||
    check(hook, test_acct, other_acct, {test_acct.missing_message()},
 | 
					    check(hook, test_acct, other_acct, {test_acct.missing_message()},
 | 
				
			||||||
          post_meta={key: value})
 | 
					          post_meta={key: value})
 | 
				
			||||||
 | 
					 | 
				
			||||||
@pytest.mark.parametrize('test_acct,other_acct', testutil.combine_values(
 | 
					 | 
				
			||||||
    ACCOUNTS,
 | 
					 | 
				
			||||||
    NOT_REQUIRED_ACCOUNTS,
 | 
					 | 
				
			||||||
))
 | 
					 | 
				
			||||||
def test_no_value_required_for_credits(hook, test_acct, other_acct):
 | 
					 | 
				
			||||||
    check(hook, test_acct, other_acct, None, check_type=PostType.CREDIT)
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue