import2ledger/import2ledger/hooks/invoice_payment.py
2017-12-30 18:11:41 -05:00

27 lines
831 B
Python

from . import HOOK_KINDS
class InvoicePaymentHook:
KIND = HOOK_KINDS.DATA_MUNGER
def __init__(self, config):
pass
def run(self, entry_data):
try:
words = iter(entry_data['description'].lower().split())
except KeyError:
return
want_words = iter(['payment', 'for', 'invoice'])
want_next = next(want_words)
for have_word in words:
if have_word == want_next:
try:
want_next = next(want_words)
except StopIteration:
try:
last_word = next(words)
except StopIteration:
pass
else:
entry_data['invoice_id'] = last_word.lstrip('#')
break