Fuckin yaldi, working kimai import 💅

This commit is contained in:
3wc
2023-11-01 19:28:55 +00:00
parent e8ff5f1411
commit ebf2dca695
4 changed files with 118 additions and 34 deletions

View File

@ -17,7 +17,8 @@ from .db import (
KimaiCustomer,
KimaiProject,
KimaiActivity,
HamsterKimaiMapping,
HamsterActivityKimaiMapping,
HamsterFactKimaiImport
)
HAMSTER_DIR = Path.home() / ".local/share/hamster"
@ -630,12 +631,13 @@ def db_():
@db_.command()
def init():
db.create_tables([KimaiCustomer, KimaiProject, KimaiActivity, HamsterKimaiMapping])
db.create_tables([KimaiCustomer, KimaiProject, KimaiActivity,
HamsterActivityKimaiMapping, HamsterFactKimaiImport])
@db_.command()
def reset():
HamsterKimaiMapping.delete().execute()
HamsterActivityKimaiMapping.delete().execute()
@db_.command()
@ -653,7 +655,6 @@ def mapping2db(mapping_path=None, global_=False):
mapping_reader = csv.reader(mapping_file)
for row in mapping_reader:
hamster_category = HamsterCategory.get(name=row[0])
hamster_activity = HamsterActivity.get(
name=row[1], category_id=hamster_category.id
@ -666,9 +667,10 @@ def mapping2db(mapping_path=None, global_=False):
except KimaiActivity.DoesNotExist:
kimai_activity = KimaiActivity.get(
name=row[4],
project_id=None
)
HamsterKimaiMapping.create(
HamsterActivityKimaiMapping.create(
hamster_activity=hamster_activity,
kimai_customer=kimai_customer,
kimai_project=kimai_project,