fix(attendance_request): enhance leave record checks for half-day attendance requests#4549
Conversation
WalkthroughThis 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)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
hrms/hr/doctype/attendance_request/attendance_request.pyhrms/hr/doctype/attendance_request/test_attendance_request.py
| if self.half_day_date == attendance_date: | ||
| filters["half_day"] = 0 |
There was a problem hiding this comment.
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.
ebfd2ed to
71a4157
Compare
asmitahase
left a comment
There was a problem hiding this comment.
Add screenshots or videos for user-facing changes in the description, it helps give a quick visual overview as to what is changed
…4549 fix(attendance_request): enhance leave record checks for half-day attendance requests (backport #4549)
Fixes #4531
Changes:
Screen.Recording.2026-05-19.at.1.34.19.PM.mov
Summary by CodeRabbit
Bug Fixes
Tests