meta_receipt: Accept paypal-id in lieu of receipt for PayPal credits.

This commit is contained in:
Brett Smith 2020-03-30 15:43:14 -04:00
parent 381160f0de
commit a0a3b04e50
2 changed files with 14 additions and 2 deletions

View file

@ -42,14 +42,24 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
receipt_error = error receipt_error = error
else: else:
return return
if not post.units.number:
post_amount = 0
elif post.units.number > 0:
post_amount = 1
else:
post_amount = -1
if post.account.is_checking(): if post.account.is_checking():
fallback_key = 'check' fallback_key = 'check'
elif (post.account.is_under('Liabilities:CreditCard') elif post.account.is_under('Liabilities:CreditCard') and post_amount == -1:
and (post.units.number or 0) < 0):
fallback_key = 'invoice' fallback_key = 'invoice'
elif post.account.is_under('Assets:PayPal') and post_amount == 1:
fallback_key = 'paypal-id'
else: else:
yield receipt_error yield receipt_error
return return
try: try:
self._check_links(txn, post, fallback_key) self._check_links(txn, post, fallback_key)
except errormod.Error as fallback_error: except errormod.Error as fallback_error:

View file

@ -59,6 +59,8 @@ ACCOUNTS = [AccountForTesting._make(t) for t in [
('Assets:Bank:CheckCard', PostType.BOTH, 'check'), ('Assets:Bank:CheckCard', PostType.BOTH, 'check'),
('Assets:Cash', PostType.BOTH, None), ('Assets:Cash', PostType.BOTH, None),
('Assets:Checking', PostType.BOTH, 'check'), ('Assets:Checking', PostType.BOTH, 'check'),
('Assets:PayPal', PostType.CREDIT, 'paypal-id'),
('Assets:PayPal', PostType.DEBIT, None),
('Assets:Savings', PostType.BOTH, None), ('Assets:Savings', PostType.BOTH, None),
('Liabilities:CreditCard', PostType.CREDIT, None), ('Liabilities:CreditCard', PostType.CREDIT, None),
('Liabilities:CreditCard', PostType.DEBIT, 'invoice'), ('Liabilities:CreditCard', PostType.DEBIT, 'invoice'),