Fix test failures and workload/websocket behavior

This commit is contained in:
beabigegg
2026-01-11 08:37:21 +08:00
parent 3bdc6ff1c9
commit f5f870da56
49 changed files with 3006 additions and 1132 deletions

View File

@@ -42,6 +42,26 @@ def get_current_week_start() -> date:
return get_week_bounds(date.today())[0]
def get_current_week_bounds() -> Tuple[date, date]:
"""
Get current week bounds for default views.
On Sundays, extend the window to include the upcoming week so that
"tomorrow" tasks are still visible in default views.
"""
week_start, week_end = get_week_bounds(date.today())
if date.today().weekday() == 6:
week_end = week_end + timedelta(days=7)
return week_start, week_end
def _extend_week_end_if_sunday(week_start: date, week_end: date) -> Tuple[date, date]:
"""Extend week window on Sunday to include upcoming week."""
if date.today().weekday() == 6 and week_start == get_current_week_start():
return week_start, week_end + timedelta(days=7)
return week_start, week_end
def determine_load_level(load_percentage: Optional[Decimal]) -> LoadLevel:
"""
Determine the load level based on percentage.
@@ -149,7 +169,7 @@ def calculate_user_workload(
if task.original_estimate:
allocated_hours += task.original_estimate
capacity_hours = Decimal(str(user.capacity)) if user.capacity else Decimal("40")
capacity_hours = Decimal(str(user.capacity)) if user.capacity is not None else Decimal("40")
load_percentage = calculate_load_percentage(allocated_hours, capacity_hours)
load_level = determine_load_level(load_percentage)
@@ -191,11 +211,11 @@ def get_workload_heatmap(
if week_start is None:
week_start = get_current_week_start()
else:
# Normalize to week start (Monday)
week_start = get_week_bounds(week_start)[0]
# Normalize to week start (Monday)
week_start = get_week_bounds(week_start)[0]
week_start, week_end = get_week_bounds(week_start)
week_start, week_end = _extend_week_end_if_sunday(week_start, week_end)
# Build user query
query = db.query(User).filter(User.is_active == True)
@@ -245,7 +265,7 @@ def get_workload_heatmap(
if task.original_estimate:
allocated_hours += task.original_estimate
capacity_hours = Decimal(str(user.capacity)) if user.capacity else Decimal("40")
capacity_hours = Decimal(str(user.capacity)) if user.capacity is not None else Decimal("40")
load_percentage = calculate_load_percentage(allocated_hours, capacity_hours)
load_level = determine_load_level(load_percentage)
@@ -297,10 +317,9 @@ def get_user_workload_detail(
if week_start is None:
week_start = get_current_week_start()
else:
week_start = get_week_bounds(week_start)[0]
week_start = get_week_bounds(week_start)[0]
week_start, week_end = get_week_bounds(week_start)
week_start, week_end = _extend_week_end_if_sunday(week_start, week_end)
# Get tasks
tasks = get_user_tasks_in_week(db, user_id, week_start, week_end)
@@ -323,7 +342,7 @@ def get_user_workload_detail(
status=task.status.name if task.status else None,
))
capacity_hours = Decimal(str(user.capacity)) if user.capacity else Decimal("40")
capacity_hours = Decimal(str(user.capacity)) if user.capacity is not None else Decimal("40")
load_percentage = calculate_load_percentage(allocated_hours, capacity_hours)
load_level = determine_load_level(load_percentage)