diff --git a/import2ledger/hooks/invoice_payment.py b/import2ledger/hooks/invoice_payment.py new file mode 100644 index 0000000..826c28a --- /dev/null +++ b/import2ledger/hooks/invoice_payment.py @@ -0,0 +1,23 @@ +class InvoicePaymentHook: + 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