diff --git a/autosort.py b/autosort.py index 74563b9..1b3347d 100644 --- a/autosort.py +++ b/autosort.py @@ -27,7 +27,7 @@ def command(profile, dry_run, verbose): unsorted = session.query(Transaction).filter(Transaction.category_id == None).all() print("Found {} unsorted transcations".format(len(unsorted))) - matched = 0 + new = [] for t in unsorted: cat_name = apply_rules(t, rules) @@ -39,13 +39,13 @@ def command(profile, dry_run, verbose): cat_id = session.query(Category).filter(Category.name == cat_name).first() if not cat_id: cat_id = add_category(cat_name, profile, session) - matched += 1 t.category_id = cat_id - session.add(t) + new.append(t) print_verbose(verbose, "-" * 90) - print(f"Automatically matched {matched} transactions") + print(f"Automatically matched {len(new)} transactions") if not dry_run: + session.bulk_save_object(new) session.commit()