Fix sort
This commit is contained in:
parent
9154039644
commit
9f6293872a
5 changed files with 58 additions and 8 deletions
|
@ -53,7 +53,7 @@ def apply_rules(t, rules):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if desc_regex:
|
if desc_regex:
|
||||||
if not re.search(desc_regext.description):
|
if not re.search(desc_regex, t.description):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return r["tags"].split(",")
|
return r["tags"].split(",")
|
||||||
|
|
12
cli
12
cli
|
@ -8,8 +8,9 @@ import importer
|
||||||
import serve
|
import serve
|
||||||
import autosort
|
import autosort
|
||||||
import validate
|
import validate
|
||||||
# import info
|
import info
|
||||||
# import report
|
import sort
|
||||||
|
#import report
|
||||||
|
|
||||||
from helper import build_database_filename, create_dirs, build_rules_filename
|
from helper import build_database_filename, create_dirs, build_rules_filename
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
@ -27,6 +28,8 @@ def cli():
|
||||||
@cli.command(name="init")
|
@cli.command(name="init")
|
||||||
@click.argument("profile_name", required=True)
|
@click.argument("profile_name", required=True)
|
||||||
def init(profile_name):
|
def init(profile_name):
|
||||||
|
create_dirs()
|
||||||
|
|
||||||
db_path = build_database_filename(profile_name)
|
db_path = build_database_filename(profile_name)
|
||||||
rule_path = build_rules_filename(profile_name)
|
rule_path = build_rules_filename(profile_name)
|
||||||
|
|
||||||
|
@ -44,12 +47,11 @@ def init(profile_name):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
create_dirs()
|
cli.add_command(sort.command)
|
||||||
# cli.add_command(sort.command)
|
|
||||||
cli.add_command(importer.command)
|
cli.add_command(importer.command)
|
||||||
cli.add_command(serve.command)
|
cli.add_command(serve.command)
|
||||||
cli.add_command(autosort.command)
|
cli.add_command(autosort.command)
|
||||||
cli.add_command(validate.command)
|
cli.add_command(validate.command)
|
||||||
# cli.add_command(info.command)
|
cli.add_command(info.command)
|
||||||
# cli.add_command(report.command)
|
# cli.add_command(report.command)
|
||||||
cli()
|
cli()
|
||||||
|
|
|
@ -29,7 +29,7 @@ def command(profile, year):
|
||||||
for sc in sub_categories:
|
for sc in sub_categories:
|
||||||
transactions = session.query(Transaction).filter(Transaction.category_id == sc.id).all()
|
transactions = session.query(Transaction).filter(Transaction.category_id == sc.id).all()
|
||||||
data[mc.name][sc.name] = format_amount(sum([x.amount for x in transactions]))
|
data[mc.name][sc.name] = format_amount(sum([x.amount for x in transactions]))
|
||||||
|
|
||||||
context = {"year": year, "data": data}
|
context = {"year": year, "data": data}
|
||||||
|
|
||||||
tpl = template("views/report.tpl", context)
|
tpl = template("views/report.tpl", context)
|
||||||
|
|
49
sort.py
Normal file
49
sort.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
from models import Transaction, Tag
|
||||||
|
from helper import get_session, create_tag
|
||||||
|
import sys
|
||||||
|
import click
|
||||||
|
|
||||||
|
from prompt_toolkit.completion import FuzzyWordCompleter
|
||||||
|
from prompt_toolkit.shortcuts import prompt
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(name="sort")
|
||||||
|
@click.option("--profile", "-p")
|
||||||
|
def command(profile):
|
||||||
|
session = get_session(profile)
|
||||||
|
tags = session.query(Tag).all()
|
||||||
|
tag_names = FuzzyWordCompleter([x.name for x in tags])
|
||||||
|
tag_lookup = {tag.name: tag for tag in tags}
|
||||||
|
|
||||||
|
unsorted = session.query(Transaction).filter(Transaction.tags == None).all()
|
||||||
|
print("Found {} unsorted transcations".format(len(unsorted)))
|
||||||
|
|
||||||
|
for t in unsorted:
|
||||||
|
print(" Name: {}".format(t.name))
|
||||||
|
print(" VWZ: {}".format(t.description))
|
||||||
|
print("Betrag: {}€".format(t.amount / 100))
|
||||||
|
try:
|
||||||
|
select = prompt("Tag: ", completer=tag_names, complete_while_typing=True)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Goodbye")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if select == "":
|
||||||
|
print("Skipping")
|
||||||
|
continue
|
||||||
|
|
||||||
|
tag = tag_lookup.get(select, None)
|
||||||
|
if not tag:
|
||||||
|
print(f"Creating new category '{select}'")
|
||||||
|
tag = create_tag(select, profile, session)
|
||||||
|
|
||||||
|
tags = session.query(Tag).all()
|
||||||
|
tag_names = FuzzyWordCompleter([x.name for x in tags])
|
||||||
|
tag_lookup = {tag.name: tag for tag in tags}
|
||||||
|
|
||||||
|
t.tags.append(tag)
|
||||||
|
session.add(t)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
print("-" * 20)
|
|
@ -56,7 +56,6 @@ def command():
|
||||||
except:
|
except:
|
||||||
print(cf.red(f" Invalid IBAN: '{rule.get('iban')}'"))
|
print(cf.red(f" Invalid IBAN: '{rule.get('iban')}'"))
|
||||||
|
|
||||||
|
|
||||||
print(cf.green(f" All rules are valid"))
|
print(cf.green(f" All rules are valid"))
|
||||||
else:
|
else:
|
||||||
print(cf.red(f" The rule file doesn't exists"))
|
print(cf.red(f" The rule file doesn't exists"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue