hooks.invoice_payment: New hook.

In the long run, this should be some kind of configurable hook to run
arbitrary regexps on arbitrary entry fields, and then on a match, add
another field with a format string using the match data.  But this is
reasonably generic for now.
This commit is contained in:
Brett Smith 2017-12-18 17:40:30 -05:00
parent 9472be10f1
commit 0734b6f7a5

View file

@ -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