meta_receipt: Accept invoice in lieu of receipt for credit card charges.
This commit is contained in:
parent
7cac21b780
commit
381160f0de
2 changed files with 22 additions and 16 deletions
|
@ -38,21 +38,25 @@ class MetaReceipt(core._RequireLinksPostingMetadataHook):
|
||||||
def post_run(self, txn: Transaction, post: data.Posting) -> errormod.Iter:
|
def post_run(self, txn: Transaction, post: data.Posting) -> errormod.Iter:
|
||||||
try:
|
try:
|
||||||
self._check_links(txn, post, 'receipt')
|
self._check_links(txn, post, 'receipt')
|
||||||
except errormod.Error as receipt_error:
|
except errormod.Error as error:
|
||||||
# Outgoing check may omit a receipt if they have a check link
|
receipt_error = error
|
||||||
# instead.
|
|
||||||
if ':Check' not in post.account:
|
|
||||||
yield receipt_error
|
|
||||||
else:
|
else:
|
||||||
|
return
|
||||||
|
if post.account.is_checking():
|
||||||
|
fallback_key = 'check'
|
||||||
|
elif (post.account.is_under('Liabilities:CreditCard')
|
||||||
|
and (post.units.number or 0) < 0):
|
||||||
|
fallback_key = 'invoice'
|
||||||
|
else:
|
||||||
|
yield receipt_error
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
self._check_links(txn, post, 'check')
|
self._check_links(txn, post, fallback_key)
|
||||||
except errormod.Error as check_error:
|
except errormod.Error as fallback_error:
|
||||||
if (receipt_error.message.endswith(" missing receipt")
|
if (receipt_error.message.endswith(f" missing {self.METADATA_KEY}")
|
||||||
and check_error.message.endswith(" missing check")):
|
and fallback_error.message.endswith(f" missing {fallback_key}")):
|
||||||
check_error.message = check_error.message.replace(
|
receipt_error.message += f" or {fallback_key}"
|
||||||
" missing check", " missing receipt or check",
|
yield receipt_error
|
||||||
)
|
|
||||||
yield check_error
|
|
||||||
else:
|
else:
|
||||||
yield receipt_error
|
yield receipt_error
|
||||||
yield check_error
|
yield fallback_error
|
||||||
|
|
|
@ -60,6 +60,8 @@ ACCOUNTS = [AccountForTesting._make(t) for t in [
|
||||||
('Assets:Cash', PostType.BOTH, None),
|
('Assets:Cash', PostType.BOTH, None),
|
||||||
('Assets:Checking', PostType.BOTH, 'check'),
|
('Assets:Checking', PostType.BOTH, 'check'),
|
||||||
('Assets:Savings', PostType.BOTH, None),
|
('Assets:Savings', PostType.BOTH, None),
|
||||||
|
('Liabilities:CreditCard', PostType.CREDIT, None),
|
||||||
|
('Liabilities:CreditCard', PostType.DEBIT, 'invoice'),
|
||||||
]]
|
]]
|
||||||
|
|
||||||
ACCOUNTS_WITH_FALLBACKS = [acct for acct in ACCOUNTS if acct.fallback_meta]
|
ACCOUNTS_WITH_FALLBACKS = [acct for acct in ACCOUNTS if acct.fallback_meta]
|
||||||
|
|
Loading…
Add table
Reference in a new issue