This commit is contained in:
Felix Breidenstein 2020-10-18 15:14:52 +02:00
parent eeea40b125
commit 78a0d1a1f7
5 changed files with 14 additions and 77 deletions

View file

@ -52,8 +52,8 @@ def command(profile, dry_run, verbose):
def apply_rules(t, rules):
for r in rules:
iban = r.get("iban")
name_regex = r.get("name_regex")
desc_regex = r.get("desc_regex")
name_regex = r.get("name")
desc_regex = r.get("description")
if iban:
if t.iban != iban:

11
cli
View file

@ -3,13 +3,12 @@ import click
import os
import sys
import sort
import importer
import serve
#import importer
#import serve
import autosort
import validate
import info
import report
# import validate
# import info
# import report
from helper import build_database_filename, create_dirs
from sqlalchemy import create_engine

View file

@ -15,7 +15,6 @@ class Transaction(Base):
iban = Column(String)
amount = Column(Integer)
description = Column(String)
category_id = Column(Integer, ForeignKey("Category.id"))
def is_positive(self):
return self.amount > 0
@ -32,23 +31,11 @@ class Transaction(Base):
return "UNKNOWN FORMAT"
class Category(Base):
__tablename__ = "Category"
id = Column(Integer, primary_key=True)
name = Column(String)
transactions = relationship("Transaction", backref="category")
parent_id = Column(Integer, ForeignKey("Category.id"))
children = relationship("Category", backref=backref("parent", remote_side=[id]))
class Tag(Base):
__tablename__ = "Tag"
name = Column(String, primary_key=True)
description = Column(String)
transactions = relationship("Transaction", backref="tags")
def __repr__(self):
return f"<Category {self.name}>"
def is_child(self):
# we are a child if we have zero children
return len(self.children) == 0
def full_name(self):
if not self.parent:
return self.name
else:
return f"{self.parent.full_name()}:{self.name}"
return f"<Tag {self.name}>"

View file

@ -4,7 +4,7 @@ from helper import get_session, format_amount
from datetime import datetime
from sqlalchemy import func
import click
from models import Transaction, Category
from models import Transaction, Tag
session = None
app = Flask(__name__)

49
sort.py
View file

@ -1,49 +0,0 @@
#! /usr/bin/env python3
from models import Transaction
from helper import get_session, add_category, get_list_of_bookable_categories
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)
categories = get_list_of_bookable_categories(session)
category_lookup = {c.full_name(): c.id for c in categories}
category_names = FuzzyWordCompleter([c.full_name() for c in categories])
unsorted = session.query(Transaction).filter(Transaction.category_id == 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("Category: ", completer=category_names, complete_while_typing=True)
except KeyboardInterrupt:
print("Goodbye")
sys.exit(0)
if select == "":
print("Skipping")
continue
cat_id = category_lookup.get(select, None)
if not cat_id:
print(f"Creating new category '{select}'")
cat_id = add_category(select, profile, session)
# Update the list of categories
categories = get_list_of_bookable_categories(session)
category_lookup = {c.full_name(): c.id for c in categories}
category_names = FuzzyWordCompleter([c.full_name() for c in categories])
t.category_id = cat_id
session.add(t)
session.commit()
print("-" * 20)