feat: enhance report data extraction and comment handling in week report generator and logger

This commit is contained in:
MarioYang 2026-01-26 16:29:06 +08:00
parent a3da684e9d
commit 0ff400c97c
2 changed files with 26 additions and 8 deletions

View File

@ -223,21 +223,35 @@ def extract_report_data_from_json(json_data, user_manager=None):
project_name = path_to_leaf[0]['name'] # First element is always the project
# Determine sub-project name (C column)
# Structure: project_head -> project_1-1 -> ... -> project_1-1-3-2 -> work_package_1 -> work_package_1-1 -> ... -> work_package_end -> leaf
# Priority: 1) First work_package (highest level), 2) Last project (lowest level), 3) "-"
sub_project_name = "-"
if len(path_to_leaf) > 2: # project -> work_package -> ... -> leaf
# Find the highest level work_package (first work_package in path)
for node in path_to_leaf[1:]: # Skip project node
if node['type'] == 'work_package':
sub_project_name = node['name']
break
first_work_package = None
first_work_package_index = None
last_project = None
last_project_index = None
# Skip the first node (root project) and last node (leaf), track level indices
for level_index, node in enumerate(path_to_leaf[1:-1], start=1):
if node['type'] == 'work_package' and first_work_package is None:
first_work_package = node['name'] # Take the first work_package found
first_work_package_index = level_index
elif node['type'] == 'project':
last_project = node['name'] # Keep updating to get the last project
last_project_index = level_index
# Apply priority logic
if first_work_package:
sub_project_name = first_work_package # Highest priority: first work_package
elif last_project:
sub_project_name = last_project # Second priority: last project
# Task name (E column) - leaf work package name
task_name = leaf_node['name']
# Format progress text with comments
progress_parts = [task_name]
if time_entry.get('comment') and time_entry['comment'].strip():
progress_parts.append(time_entry['comment'].strip())
progress_parts.append(f" - {time_entry['comment'].strip()}")
progress_text = '\n'.join(progress_parts)

View File

@ -372,7 +372,11 @@ class WeekWorkPackageLogger:
# Extract basic information
spent_on = entry.get('spentOn', 'Unknown')
comment_raw = entry.get('comment', '')
comment = comment_raw.strip() if isinstance(comment_raw, str) else ''
# Extract raw comment from comment object structure
if isinstance(comment_raw, dict):
comment = comment_raw.get('raw', '').strip()
else:
comment = '' if comment_raw is None else str(comment_raw).strip()
hours_str = entry.get('hours', 'PT0H')
hours = self._parse_duration(hours_str)