feat: sort time entries by ID in tree structure building

This commit is contained in:
MarioYang 2026-01-28 09:48:02 +08:00
parent 5a3824a85f
commit fffef17056
1 changed files with 4 additions and 1 deletions

View File

@ -617,6 +617,9 @@ class WeekWorkPackageLogger:
def _build_tree_structure(self, time_entries: List[Dict]) -> Dict[str, TreeNode]:
"""Build tree structure from time entries"""
# Sort time entries by ID ascending (oldest first)
time_entries_sorted = sorted(time_entries, key=lambda x: int(x.get('id', 0)))
# Create root nodes for projects
project_trees = {}
@ -625,7 +628,7 @@ class WeekWorkPackageLogger:
# which may not be the root project but a child project in the hierarchy
project_entries = defaultdict(lambda: defaultdict(list))
for entry in time_entries:
for entry in time_entries_sorted:
try:
# Extract basic information
spent_on = entry.get('spentOn', 'Unknown')