(20260219) Updarted APIs to now show last-in time and loc also.

This commit is contained in:
2026-02-19 14:48:41 +05:30
parent 81021a4b38
commit d8aaf942b2
7 changed files with 360 additions and 218 deletions
+18 -5
View File
@@ -569,6 +569,11 @@ def compute_work_done(
if work_reports[user_id][punch_date].get("first_in") is None:
work_reports[user_id][punch_date]["first_in"] = punch_ts
work_reports[user_id][punch_date]["first_in_loc"] = punch_loc
work_reports[user_id][punch_date]["last_in"] = punch_ts
work_reports[user_id][punch_date]["last_in_loc"] = punch_loc
else:
work_reports[user_id][punch_date]["last_in"] = punch_ts
work_reports[user_id][punch_date]["last_in_loc"] = punch_loc
# Handle the last out time:
if row["I/O Type"] == "Out":
@@ -589,19 +594,21 @@ def compute_work_done(
# Extract, clean and compute punch timing:
first_in = punch_info.get("first_in")
first_in_loc = punch_info.get("first_in_loc")
last_in = punch_info.get("last_in")
last_in_loc = punch_info.get("last_in_loc")
last_out = punch_info.get("last_out")
last_out_loc = punch_info.get("last_out_loc")
# When the user has a valid in-time, but no known out time,
# we assume that he worked a full day:
if first_in is not None and not last_out:
if first_in is not None and last_out is None:
last_out = first_in + min_work_seconds
work_seconds = last_out - first_in
work_seconds = min_work_seconds
work_ot_seconds = 0.0
# When the user has neither an in-time, nor an out-time,
# we assume that he was absent the whole day:
elif not first_in and not last_out:
elif first_in is None and last_out is None:
work_seconds = 0.0
work_ot_seconds = 0.0
@@ -628,6 +635,8 @@ def compute_work_done(
"work_date": punch_date,
"first_in": first_in,
"first_in_loc": first_in_loc,
"last_in": last_in,
"last_in_loc": last_in_loc,
"last_out": last_out,
"last_out_loc": last_out_loc,
"work_seconds": work_seconds,
@@ -647,6 +656,7 @@ def compute_work_done(
async def sync_attendance_to_tcaoff(
tcaoff_client: AsyncTheCAOffice,
cosec_in_out_summary: dict,
chunk_size: int = 10,
verbose: bool = False
) -> Dict[str, int]:
@@ -655,6 +665,7 @@ async def sync_attendance_to_tcaoff(
:param tcaoff_client: The asynchronous client object that interfaces with TCAOFF.
:param cosec_in_out_summary: he table that contains all the work done by all the employees on the date-range that
was selected.
:param chunk_size: The number of attendance marking requests to fire concurrently.
:param verbose: If True, internal debugging print will be more verbose.
:return: The dict that gives you the count of the successful and failed attendance marking API calls.
"""
@@ -707,9 +718,11 @@ async def sync_attendance_to_tcaoff(
json_notes = {
"cosec": {
"workSeconds": wr["work_seconds"],
"totHours": wr["work_hours"],
"workHours": wr["work_hours"],
"firstIn": wr["first_in"],
"firstInLoc": wr["first_in_loc"],
"lastIn": wr["last_in"],
"lastInLoc": wr["last_in_loc"],
"lastOut": wr["last_out"],
"lastOutLoc": wr["last_out_loc"],
}
@@ -724,7 +737,7 @@ async def sync_attendance_to_tcaoff(
yield lst[i:i + size]
count = 0
for chunk in chunks(tasks[:], size = 25):
for chunk in chunks(tasks[:], size = chunk_size):
count += 1
printer("Task Chunk:", count)
_res = await asyncio.gather(*chunk)