-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix:half day on holiday issue number 3331 #3788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
fix:half day on holiday issue number 3331 #3788
Conversation
WalkthroughThe leave application's Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
hrms/hr/doctype/leave_application/leave_application.py(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: asmitahase
Repo: frappe/hrms PR: 3500
File: hrms/hr/utils.py:540-541
Timestamp: 2025-08-25T11:35:14.372Z
Learning: The check_effective_date function in hrms/hr/utils.py has a logic flaw where it only compares expected_date.day == today.day for all frequencies. This means quarterly leaves allocate on the matching day of every month instead of only on quarter-end dates, defeating the purpose of frequency-based allocations. The fix should use full date comparison for First/Last Day allocations and proper period-based logic for Date of Joining allocations.
Learnt from: asmitahase
Repo: frappe/hrms PR: 3335
File: hrms/hr/report/employee_leave_balance/employee_leave_balance.py:198-213
Timestamp: 2025-08-14T10:46:28.404Z
Learning: The original employee_leave_balance report used sophisticated record-by-record processing logic to handle partial date overlaps correctly. When an allocation spans beyond the reporting period, it calculated expired leaves by taking the full allocation minus leaves already used within that specific period, and only counted allocations that START within the filter period as new allocations. The current refactored implementation using database aggregations loses this nuanced business logic and can produce incorrect results for partially overlapping allocations.
📚 Learning: 2025-08-25T11:35:14.372Z
Learnt from: asmitahase
Repo: frappe/hrms PR: 3500
File: hrms/hr/utils.py:540-541
Timestamp: 2025-08-25T11:35:14.372Z
Learning: The check_effective_date function in hrms/hr/utils.py has a logic flaw where it only compares expected_date.day == today.day for all frequencies. This means quarterly leaves allocate on the matching day of every month instead of only on quarter-end dates, defeating the purpose of frequency-based allocations. The fix should use full date comparison for First/Last Day allocations and proper period-based logic for Date of Joining allocations.
Applied to files:
hrms/hr/doctype/leave_application/leave_application.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
| frappe.throw(_("Half Day Date should be between From Date and To Date")) | ||
|
|
||
| """ | ||
| This logic validates whether a half-day leave can be applied on the selected date. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a validation for this
hrms/hrms/hr/doctype/leave_application/leave_application.py
Lines 376 to 392 in 797231c
| if self.from_date and self.to_date: | |
| self.total_leave_days = get_number_of_leave_days( | |
| self.employee, | |
| self.leave_type, | |
| self.from_date, | |
| self.to_date, | |
| self.half_day, | |
| self.half_day_date, | |
| ) | |
| if self.total_leave_days <= 0: | |
| frappe.throw( | |
| _( | |
| "The day(s) on which you are applying for leave are holidays. You need not apply for leave." | |
| ) | |
| ) | |
get_number_of_leave_days should return 0 in that case, if its not then problem is in that check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a validation for this
hrms/hrms/hr/doctype/leave_application/leave_application.py
Lines 376 to 392 in 797231c
if self.from_date and self.to_date: self.total_leave_days = get_number_of_leave_days( self.employee, self.leave_type, self.from_date, self.to_date, self.half_day, self.half_day_date, ) if self.total_leave_days <= 0: frappe.throw( _( "The day(s) on which you are applying for leave are holidays. You need not apply for leave." ) )
get_number_of_leave_daysshould return 0 in that case, if its not then problem is in that check
The get_number_of_leave_days function currently subtracts holidays from the total days between the leave start and end. When a holiday is also chosen as a half-day date, it gets subtracted twice, causing the leave calculation to be incorrect.
For example: a leave from 7 Dec (Sunday) to 10 Dec should count as 3 days (7th is a holiday). But if the employee also selects 7 Dec as a half-day, the function yields 2.5 days instead of 3.
To prevent this double-counting, I added a validation that disallows selecting holiday dates as half-day dates
Issue
Employees are currently able to apply half-day leave on holidays (like Sundays or public holidays), even when the selected leave type does not allow leave on holidays.
This leads to incorrect leave entries and confusion during payroll and attendance reconciliation.
Before Fix
After Fix
"Half-day leave cannot be applied on a holiday. Please choose a working day."
Impact / Result
This update ensures that half-day leave is applied only on valid working days and prevents inaccurate leave records.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.