Fix mapping import, show mapping count on list

This commit is contained in:
3wc
2023-10-29 13:37:40 +00:00
parent f8f83ce4d4
commit ccbbc80116
2 changed files with 31 additions and 9 deletions

View File

@ -95,7 +95,6 @@ def list_category_activities(ids):
def tidy_categories():
""" Remove categories with no activities """
# Create a subquery to calculate the count of activities per category
subquery = (
HamsterCategory
.select(HamsterCategory, fn.COUNT(HamsterActivity.id).alias('activities_count'))
@ -104,7 +103,6 @@ def tidy_categories():
.alias('subquery')
)
# Use the subquery to filter categories where activities_count is 0
categories = (
HamsterCategory
.select()
@ -601,17 +599,20 @@ def reset():
@db_.command()
@click.option('-g', '--global', 'global_', help='Does this file contain mappings to global activties', is_flag=True)
@click.option('--mapping-path', help='Mapping file')
def import_csv(mapping_path=None, global_=False):
def mapping2db(mapping_path=None, global_=False):
mapping_file = _get_kimai_mapping_file(mapping_path, None)
next(mapping_file)
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])
hamster_activity = HamsterActivity.get(name=row[1],
category_id=hamster_category.id)
kimai_customer = KimaiCustomer.get(name=row[2])
kimai_project = KimaiProject.get(name=row[3],
customer_id=kimai_customer.id)
try:
kimai_activity = KimaiActivity.get(
name=row[4],