diff --git a/daily_timesheet.py b/daily_timesheet.py index 9bb3296..f21d31f 100755 --- a/daily_timesheet.py +++ b/daily_timesheet.py @@ -102,7 +102,8 @@ def notify_session_expired(): print("SESSION EXPIRED — update SESSION_ID di run_daily.sh") -def search_task(session_id: str, code: str, project_id: int) -> tuple[int, str] | None: +def search_task_in_project(session_id: str, code: str, project_id: int) -> tuple[int, str] | None: + """Cari task di satu project spesifik.""" payload = { "id": 1, "jsonrpc": "2.0", "method": "call", "params": { @@ -130,6 +131,26 @@ def search_task(session_id: str, code: str, project_id: int) -> tuple[int, str] return tuple(items[0]) if items else None +def search_task(session_id: str, code: str, project_id: int) -> tuple[int, str, int] | None: + """ + Cari task mulai dari project default repo. + Kalau tidak ketemu, fallback cari di semua project lain. + Return (task_id, task_name, actual_project_id). + """ + result = search_task_in_project(session_id, code, project_id) + if result: + return result[0], result[1], project_id + + for name, pid in PROJECT_MAP.items(): + if pid == project_id: + continue + result = search_task_in_project(session_id, code, pid) + if result: + return result[0], result[1], pid + + return None + + def upload_timesheet(session_id: str, entry: dict, user_id: int) -> int: payload = { "id": 1, "jsonrpc": "2.0", "method": "call", @@ -294,16 +315,19 @@ def main(): task = task_cache[cache_key] if not task: not_found.append(c) - print(f" NOT FOUND [{c['code']}] di project {c['project']} ({c['hash']})") + print(f" NOT FOUND [{c['code']}] di semua project ({c['hash']})") continue - task_id, task_name = task - key = (task_id, c["project_id"]) + task_id, task_name, actual_project_id = task + if actual_project_id != c["project_id"]: + actual_name = next(k for k, v in PROJECT_MAP.items() if v == actual_project_id) + print(f" FALLBACK [{c['code']}] tidak ada di {c['project']}, ditemukan di {actual_name}") + key = (task_id, actual_project_id) groups[key]["descriptions"].append(c["description"]) groups[key]["timestamps"].append(c["dt"]) groups[key]["count"] += 1 - groups[key]["project_id"] = c["project_id"] - groups[key]["project"] = c["project"] + groups[key]["project_id"] = actual_project_id + groups[key]["project"] = next(k for k, v in PROJECT_MAP.items() if v == actual_project_id) groups[key]["task_id"] = task_id groups[key]["task_name"] = task_name groups[key]["date"] = c["date"]