Skip to content

feat: Credit present on holiday against absence #3425

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

KhaledBinAmir
Copy link
Contributor

@KhaledBinAmir KhaledBinAmir commented Aug 3, 2025

Description
This pull request introduces a feature to automatically compensate employees who work on a holiday by offsetting an absent day within the same payroll period.

Problem
Currently, when "Include Holidays in Total Working Days" is disabled in Payroll Settings, there is no automated way to credit an employee who is marked "Present" on a holiday. The standard workaround is to create a manual Compensatory Leave Request, which adds administrative overhead. This PR solves that by making the process automatic.

Solution
This feature enhances the functionality of the existing "Consider Marked Attendance on Holidays" checkbox in Payroll Settings, giving it a dual purpose based on its context:

When "Include Holidays in Total Working Days" is DISABLED: If this checkbox is checked, any employee marked "Present" on a holiday will have their absent_days count reduced by 1 in the Salary Slip calculation. This effectively treats working on a holiday as a compensatory day.

When "Include Holidays in Total Working Days" is ENABLED: The original functionality is preserved. If checked, an employee marked "Absent" on a holiday will have their payment days deducted.

To ensure clarity for users, the description of the "Consider Marked Attendance on Holidays" checkbox has been updated to explain both behaviors.

Changes Made
hrms/payroll/doctype/salary_slip/salary_slip.py: Modified the attendance calculation logic to handle the new compensatory credit scenario.

hrms/payroll/doctype/payroll_settings/payroll_settings.json: Updated the description of the consider_marked_attendance_on_holidays field to reflect its dual functionality.

Summary by CodeRabbit

  • New Features
    • Improved payroll attendance handling for holidays, allowing separate configuration for deducting pay on absences during holidays and crediting presence on holidays.
  • Bug Fixes
    • Enhanced accuracy in calculating leave without pay and attendance on holidays, ensuring payroll reflects the updated settings.
  • Documentation
    • Updated description in payroll settings to clarify how attendance on holidays affects payroll calculations.

Consider Present on Holidays
Consider Present on Holidays
Consider Present on Holiday
Copy link

coderabbitai bot commented Aug 3, 2025

Walkthrough

The changes refine payroll attendance handling for holidays. The payroll settings JSON updates the description and removes a dependency for a holiday attendance field. In the salary slip Python logic, the single variable for marking attendance on holidays is split into two: one for considering absences and another for crediting presence, with corresponding updates to method signatures and internal logic.

Changes

Cohort / File(s) Change Summary
Payroll Settings Description Update
hrms/payroll/doctype/payroll_settings/payroll_settings.json
Updated the description text for the holiday attendance field to clarify behavior based on holiday inclusion in working days; removed the "depends_on" attribute.
Salary Slip Attendance Logic Refactor
hrms/payroll/doctype/salary_slip/salary_slip.py
Split the holiday attendance logic into two variables: one for considering absences on holidays and another for crediting presence; updated method signatures, internal logic, and attendance record filtering accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Employee
    participant SalarySlip
    participant PayrollSettings

    Employee->>SalarySlip: Request working days details
    SalarySlip->>PayrollSettings: Fetch holiday attendance settings
    PayrollSettings-->>SalarySlip: Return consider_absent_on_holidays, credit_present_on_holidays
    SalarySlip->>SalarySlip: Get attendance records (all statuses)
    SalarySlip->>SalarySlip: Calculate absent and present days
    alt credit_present_on_holidays is true
        SalarySlip->>SalarySlip: Credit present/half-day attendance on holidays
    else consider_absent_on_holidays is true
        SalarySlip->>SalarySlip: Deduct pay for absent on holidays
    else
        SalarySlip->>SalarySlip: Skip holidays for absent calculation
    end
    SalarySlip-->>Employee: Return working days and absence details
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

In the warren where payrolls hop,
Holidays now get a finer crop.
Absence and presence, split with care,
Two new carrots for bunnies to compare!
Salary slips crunch numbers anew,
With logic as crisp as morning dew.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb9cd3e and 51e3f83.

📒 Files selected for processing (1)
  • hrms/payroll/doctype/salary_slip/salary_slip.py (8 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
hrms/payroll/doctype/salary_slip/salary_slip.py

718-718: Blank line contains whitespace

Remove whitespace from blank line

(W293)


727-727: Blank line contains whitespace

Remove whitespace from blank line

(W293)

🪛 GitHub Actions: Linters
hrms/payroll/doctype/salary_slip/salary_slip.py

[error] 461-730: pre-commit hook 'trailing-whitespace' and 'ruff-format' failed and automatically fixed trailing whitespace and formatting issues in this file. Run 'pre-commit run --all-files' locally to reproduce.

⏰ 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). (3)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Summary
🔇 Additional comments (5)
hrms/payroll/doctype/salary_slip/salary_slip.py (5)

431-440: LGTM! Clean separation of holiday attendance logic.

The refactoring correctly implements the dual behavior described in the PR objectives. The two variables now clearly distinguish between:

  • consider_absent_on_holidays: Deduct payment for absences on holidays (when holidays are included in working days)
  • credit_present_on_holidays: Credit present attendance on holidays against absent days (when holidays are excluded from working days)

463-465: Method signature updated correctly.

The call to calculate_lwp_ppl_and_absent_days_based_on_attendance now properly passes both consider_absent_on_holidays and credit_present_on_holidays parameters, maintaining consistency with the separated logic.


501-504: Parameter update is consistent with the refactoring.

The get_half_absent_days method call correctly uses the new consider_absent_on_holidays parameter, maintaining the existing logic for handling half-absent days on holidays.


525-541: Method signature and logic updated correctly.

The get_half_absent_days method properly uses the renamed consider_absent_on_holidays parameter while preserving the existing logic for excluding holidays from half-day absent calculations when appropriate.


696-700: Query simplification aligns with new attendance processing logic.

Removing the status filter allows the calling method to process all attendance records, which is necessary for the new credit logic that needs to evaluate both present and absent attendance on holidays.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🔭 Outside diff range comments (1)
hrms/payroll/doctype/salary_slip/salary_slip.py (1)

461-730: Fix code formatting issues.

The pre-commit hook 'ruff-format' failed. Please run pre-commit run --all-files locally to apply the required formatting fixes before pushing.

🧹 Nitpick comments (1)
hrms/payroll/doctype/salary_slip/salary_slip.py (1)

723-739: Holiday attendance logic correctly implements the PR objectives.

The implementation properly handles:

  • Crediting present attendance on holidays against absent days
  • Accounting for half-day attendance with appropriate fractions
  • Skipping certain attendance types when appropriate

Consider adding validation to prevent the absent count from going negative:

 if d.status == "Present":
-    absent -= 1
+    absent = max(0, absent - 1)
 elif d.status == "Half Day":
-    absent -= (1 - daily_wages_fraction_for_half_day)
+    absent = max(0, absent - (1 - daily_wages_fraction_for_half_day))

This ensures that excessive holiday work doesn't result in negative absent days.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 578dbe2 and 2992aac.

📒 Files selected for processing (2)
  • hrms/payroll/doctype/payroll_settings/payroll_settings.json (2 hunks)
  • hrms/payroll/doctype/salary_slip/salary_slip.py (8 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
hrms/payroll/doctype/salary_slip/salary_slip.py

[error] 461-730: pre-commit hook 'ruff-format' failed: 1 file reformatted automatically. Run 'pre-commit run --all-files' locally to apply fixes.

⏰ 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). (3)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Summary
🔇 Additional comments (5)
hrms/payroll/doctype/payroll_settings/payroll_settings.json (2)

148-148: Description update clarifies dual behavior effectively.

The updated description clearly explains how the field behaves differently based on the "Include holidays in total working days" setting. This improves user understanding of the feature.


148-152: AI summary mentions "depends_on" removal, but it's not reflected in the code.

The AI summary states that the "depends_on" attribute was removed from this field, but the annotated code only shows a description change. This field doesn't appear to have had a "depends_on" attribute to begin with.

Likely an incorrect or invalid review comment.

hrms/payroll/doctype/salary_slip/salary_slip.py (3)

431-440: Variable naming is clear and logic separation is appropriate.

The separation of consider_absent_on_holidays and credit_present_on_holidays based on the include_holidays_in_total_working_days setting is logical and aligns with the PR objectives.


525-525: Parameter rename is consistent with the new naming convention.

The method signature and logic have been properly updated to use consider_absent_on_holidays.

Also applies to: 539-540


696-699: Removal of status filter is appropriate for the new logic.

Fetching all attendance records is necessary to process both "Present" and "Absent" statuses on holidays according to the new business logic.

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.

1 participant