def query_match(payee): """Query a match for payee line as long as a correct one is not entered. """ set_completer(sorted(complete_matches(payee))) while True: match = quick_input('Match') if match.isspace(): # Go back, discard entered category print(2 * CLEAR, end='') break if not tags.is_match(match, payee): print(CLEAR + '%s Match rejected: %s' % (TERM.red('✖'), diff(payee, match, TERM, as_error=True))) else: print(CLEAR + "%s Match accepted: %s" % (TERM.green('✔'), str(match) if match else TERM.red('<none>'))) break set_completer() return match
def query_match(payee): """Query a match for payee line as long as a correct one is not entered. """ set_completer(sorted(complete_matches(payee))) while True: match = quick_input('Match') if match.isspace(): # Go back, discard entered category print(2 * CLEAR, end='') break if not tags.is_match(match, payee): print(CLEAR + '%s Match rejected: %s' % (TERM.red('✖'), diff(payee, match, TERM, as_error=True))) else: print( CLEAR + "%s Match accepted: %s" % (TERM.green('✔'), str(match) if match else TERM.red('<none>'))) break set_completer() return match
def process_transaction(t, cached_tag, cached_match, options): """Print transaction. Tag it if it's untagged or if audit mode is True. """ tag = cached_tag match = cached_match pad_width = 8 print('Amount..: %s' % (TERM.green(str(t['amount'])) if (t['amount'] and float(t['amount']) > 0) else TERM.red(str(t['amount'])))) print('Payee...: %s' % (diff(cached_match, t['payee'], TERM) if cached_match else t['payee'] or TERM.red('<none>'))) for field in ('memo', 'number'): if t[field]: print('%s: %s' % (field.title().ljust(pad_width, '.'), t[field])) edit = False audit = options.get('audit', False) if tag: if audit: msg = "Edit '%s' category" % TERM.green(cached_tag) edit = quick_input(msg, 'yN') == 'Y' else: print('%s: %s' % ('Category'.ljust(pad_width, '.'), tag)) if t['payee']: while True: # Query for tag if no cached tag or edit if not cached_tag or edit: tag = query_tag(cached_tag) print('Category: %s' % (TERM.green(tag) if tag else TERM.red('<none>'))) # Query match if tag entered or edit if (tag != cached_tag) or edit: match = query_match(t['payee']) if not match.isspace(): break else: break return tag, match