WIP
This commit is contained in:
parent
eeea40b125
commit
78a0d1a1f7
5 changed files with 14 additions and 77 deletions
|
@ -52,8 +52,8 @@ def command(profile, dry_run, verbose):
|
||||||
def apply_rules(t, rules):
|
def apply_rules(t, rules):
|
||||||
for r in rules:
|
for r in rules:
|
||||||
iban = r.get("iban")
|
iban = r.get("iban")
|
||||||
name_regex = r.get("name_regex")
|
name_regex = r.get("name")
|
||||||
desc_regex = r.get("desc_regex")
|
desc_regex = r.get("description")
|
||||||
|
|
||||||
if iban:
|
if iban:
|
||||||
if t.iban != iban:
|
if t.iban != iban:
|
||||||
|
|
11
cli
11
cli
|
@ -3,13 +3,12 @@ import click
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import sort
|
#import importer
|
||||||
import importer
|
#import serve
|
||||||
import serve
|
|
||||||
import autosort
|
import autosort
|
||||||
import validate
|
# import validate
|
||||||
import info
|
# import info
|
||||||
import report
|
# import report
|
||||||
|
|
||||||
from helper import build_database_filename, create_dirs
|
from helper import build_database_filename, create_dirs
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
|
25
models.py
25
models.py
|
@ -15,7 +15,6 @@ class Transaction(Base):
|
||||||
iban = Column(String)
|
iban = Column(String)
|
||||||
amount = Column(Integer)
|
amount = Column(Integer)
|
||||||
description = Column(String)
|
description = Column(String)
|
||||||
category_id = Column(Integer, ForeignKey("Category.id"))
|
|
||||||
|
|
||||||
def is_positive(self):
|
def is_positive(self):
|
||||||
return self.amount > 0
|
return self.amount > 0
|
||||||
|
@ -32,23 +31,11 @@ class Transaction(Base):
|
||||||
return "UNKNOWN FORMAT"
|
return "UNKNOWN FORMAT"
|
||||||
|
|
||||||
|
|
||||||
class Category(Base):
|
class Tag(Base):
|
||||||
__tablename__ = "Category"
|
__tablename__ = "Tag"
|
||||||
id = Column(Integer, primary_key=True)
|
name = Column(String, primary_key=True)
|
||||||
name = Column(String)
|
description = Column(String)
|
||||||
transactions = relationship("Transaction", backref="category")
|
transactions = relationship("Transaction", backref="tags")
|
||||||
parent_id = Column(Integer, ForeignKey("Category.id"))
|
|
||||||
children = relationship("Category", backref=backref("parent", remote_side=[id]))
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Category {self.name}>"
|
return f"<Tag {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}"
|
|
||||||
|
|
2
serve.py
2
serve.py
|
@ -4,7 +4,7 @@ from helper import get_session, format_amount
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
import click
|
import click
|
||||||
from models import Transaction, Category
|
from models import Transaction, Tag
|
||||||
|
|
||||||
session = None
|
session = None
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
49
sort.py
49
sort.py
|
@ -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)
|
|
Loading…
Add table
Reference in a new issue