meta_receipt: Correctly fall back to other metadata on zero-value postings.
RT#10633.
This commit is contained in:
parent
4437a130d6
commit
600c9d9d6f
2 changed files with 20 additions and 10 deletions
|
@ -59,23 +59,16 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
|
|||
else:
|
||||
return
|
||||
|
||||
if not post.units.number:
|
||||
post_amount = 0
|
||||
elif post.units.number > 0:
|
||||
post_amount = 1
|
||||
else:
|
||||
post_amount = -1
|
||||
|
||||
check_method: _CheckMethod = self._check_links
|
||||
if post.account.is_checking():
|
||||
if post_amount == -1:
|
||||
if post.is_debit():
|
||||
check_method = self._check_check_id
|
||||
fallback_key = 'check-id'
|
||||
else:
|
||||
fallback_key = 'check'
|
||||
elif post.account.is_credit_card() and post_amount == -1:
|
||||
elif post.account.is_credit_card() and not post.is_credit():
|
||||
fallback_key = 'invoice'
|
||||
elif post.account.is_under('Assets:PayPal') and post_amount == 1:
|
||||
elif post.account.is_under('Assets:PayPal') and not post.is_debit():
|
||||
fallback_key = 'paypal-id'
|
||||
else:
|
||||
yield receipt_error
|
||||
|
|
|
@ -326,3 +326,20 @@ def test_bad_type_check_id_on_txn(hook, test_acct, other_acct, 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()},
|
||||
post_meta={key: value})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test_acct,other_acct,value', testutil.combine_values(
|
||||
ACCOUNTS_WITH_LINK_FALLBACK,
|
||||
NOT_REQUIRED_ACCOUNTS,
|
||||
testutil.LINK_METADATA_STRINGS,
|
||||
))
|
||||
def test_fallback_on_zero_amount_postings(hook, test_acct, other_acct, value):
|
||||
# Unfortunately it does happen that we get donations that go 100% to
|
||||
# banking fees, and our importer writes a zero-amount posting to the
|
||||
# Assets account.
|
||||
txn = testutil.Transaction(postings=[
|
||||
('Income:Donations', '-.1'),
|
||||
('Expenses:BankingFees', '.1'),
|
||||
(test_acct.name, 0, {test_acct.fallback_meta: value}),
|
||||
])
|
||||
assert not list(hook.run(txn))
|
||||
|
|
Loading…
Reference in a new issue