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:
parent
9472be10f1
commit
0734b6f7a5
1 changed files with 23 additions and 0 deletions
23
import2ledger/hooks/invoice_payment.py
Normal file
23
import2ledger/hooks/invoice_payment.py
Normal 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
|
Loading…
Reference in a new issue