Skip to content

fix(attendance_request): enhance leave record checks for half-day attendance requests#4549

Merged
deepeshgarg007 merged 1 commit into
frappe:developfrom
krishna-254:fix/attendance-request-half-day-requests
May 25, 2026
Merged

fix(attendance_request): enhance leave record checks for half-day attendance requests#4549
deepeshgarg007 merged 1 commit into
frappe:developfrom
krishna-254:fix/attendance-request-half-day-requests

Conversation

@krishna-254
Copy link
Copy Markdown
Collaborator

@krishna-254 krishna-254 commented May 18, 2026

Fixes #4531
Changes:

  • fixed status change for a day which has half-day leave, and the other half is being marked as absent due to auto attendance.
  • It did not let us add an attendance request for the above condition.
Screen.Recording.2026-05-19.at.1.34.19.PM.mov

Summary by CodeRabbit

  • Bug Fixes

    • Improved half-day attendance request handling: absent half-days can now be updated to present and avoid incorrect "unchanged" skips
    • Tightened leave validation to accurately detect approved leave spanning attendance dates, including half-day considerations
    • Better behavior when shift auto-attendance is enabled for missing check-ins
  • Tests

    • Added tests covering half-day absent→present updates and shift auto-attendance half-day scenarios

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Walkthrough

This pull request refines half-day attendance handling in the AttendanceRequest doctype. When an existing half-day attendance record has one half marked as absent and an attendance request is submitted for that same half-day, the system now converts the other-half status from absent to present. The leave-checking logic is tightened to properly filter half-day leave records by date and half-day flags. The status-unchanged detection is adjusted so half-day cases with absent other-half status are not skipped, enabling the conversion path. Two new tests validate the behavior: one for basic half-day absent-to-present conversion and another for shift auto-attendance with half-day leave and missing attendance inputs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change—enhancing leave record checks for half-day attendance requests—which directly aligns with the primary objective of the PR.
Linked Issues check ✅ Passed The code changes directly address issue #4531 by updating leave/attendance status checks to allow attendance requests in half-day scenarios with auto shift sync, fixing the restriction that previously blocked creation.
Out of Scope Changes check ✅ Passed All code changes are scoped to the attendance request half-day logic and related tests, with no unrelated modifications beyond the objectives in issue #4531.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@hrms/hr/doctype/attendance_request/attendance_request.py`:
- Around line 250-251: The condition that sets filters["half_day"] only checks
self.half_day_date and can misfire when the checkbox self.half_day is False but
a stale date remains; update the logic in attendance_request.py (where
self.half_day and self.half_day_date are used) to first verify self.half_day is
truthy before comparing dates (e.g., only set filters["half_day"] = 0 when both
self.half_day is True and self.half_day_date == attendance_date), and ensure you
handle None/empty values for self.half_day_date to avoid false matches.

In `@hrms/hr/doctype/attendance_request/test_attendance_request.py`:
- Around line 282-284: The linter flags the use of frappe.get_doc(dict(...)) in
the test (variable leave_type) — replace the dict call with keyword arguments to
satisfy the Semgrep rule; call frappe.get_doc with doctype="Leave Type" and
leave_type_name="Test Half Day Leave" (i.e., frappe.get_doc(doctype="Leave
Type", leave_type_name="Test Half Day Leave").insert()) so the leave_type
creation no longer uses get_doc(dict(...)).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcc8586c-6cf4-42a6-8ae9-43f2aa7b1e4e

📥 Commits

Reviewing files that changed from the base of the PR and between 6db4a95 and ebfd2ed.

📒 Files selected for processing (2)
  • hrms/hr/doctype/attendance_request/attendance_request.py
  • hrms/hr/doctype/attendance_request/test_attendance_request.py

Comment on lines +250 to +251
if self.half_day_date == attendance_date:
filters["half_day"] = 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Missing self.half_day check could incorrectly exclude half-day leave records.

If self.half_day is False but self.half_day_date retains a stale value (e.g., user unchecked the checkbox after setting a date), this condition may incorrectly exclude half-day leave records, allowing a conflicting attendance request to proceed.

🐛 Proposed fix
-		if self.half_day_date == attendance_date:
+		if self.half_day and self.half_day_date == attendance_date:
 			filters["half_day"] = 0
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hrms/hr/doctype/attendance_request/attendance_request.py` around lines 250 -
251, The condition that sets filters["half_day"] only checks self.half_day_date
and can misfire when the checkbox self.half_day is False but a stale date
remains; update the logic in attendance_request.py (where self.half_day and
self.half_day_date are used) to first verify self.half_day is truthy before
comparing dates (e.g., only set filters["half_day"] = 0 when both self.half_day
is True and self.half_day_date == attendance_date), and ensure you handle
None/empty values for self.half_day_date to avoid false matches.

Comment thread hrms/hr/doctype/attendance_request/test_attendance_request.py Outdated
@krishna-254 krishna-254 force-pushed the fix/attendance-request-half-day-requests branch from ebfd2ed to 71a4157 Compare May 18, 2026 11:48
Copy link
Copy Markdown
Member

@asmitahase asmitahase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add screenshots or videos for user-facing changes in the description, it helps give a quick visual overview as to what is changed

@deepeshgarg007 deepeshgarg007 merged commit 5a64749 into frappe:develop May 25, 2026
13 checks passed
deepeshgarg007 added a commit that referenced this pull request May 25, 2026
…4549

fix(attendance_request): enhance leave record checks for half-day attendance requests (backport #4549)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with Half-Day Leave and Attendance Request Restriction After Auto Shift Sync

3 participants