Skip to content

fix: allocate correct quarterly earned leaves #3428

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 9 commits into
base: develop
Choose a base branch
from

Conversation

asmitahase
Copy link
Collaborator

@asmitahase asmitahase commented Aug 4, 2025

  • Calculates passed quarters and hence quarterly earned leaves separately from months.
  • Calculates correct number of quarterly leaves based on passed quarters

Summary by CodeRabbit

  • New Features

    • Added support for quarterly earned leave allocation in addition to monthly allocation.
    • Leave Type form now updates "allocate on day" options based on the selected earned leave frequency.
  • Tests

    • Added tests to verify quarterly earned leave allocation behavior under various scenarios.

Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

Support for quarterly earned leave allocation was introduced alongside existing monthly allocation. This includes new backend methods for quarterly leave calculations, refactoring of date helper functions, frontend form updates to restrict allocation options based on frequency, and new/updated tests validating quarterly leave allocation scenarios. No unrelated control flow or error handling changes were made.

Changes

Cohort / File(s) Change Summary
Quarterly Earned Leave Calculation Logic
hrms/hr/doctype/leave_policy_assignment/leave_policy_assignment.py
Extended leave allocation logic to support quarterly earned leave frequency. Added new methods for quarterly leave calculation, refactored date helper into a public method, and introduced a helper to check allocation applicability per quarter. Updated imports accordingly.
Frontend Form Behavior
hrms/hr/doctype/leave_type/leave_type.js
Added an event handler to dynamically adjust "allocate_on_day" field options based on the selected "earned_leave_frequency" value, limiting options for non-monthly frequencies to "First Day" and "Last Day."
Quarterly Leave Allocation Tests
hrms/hr/doctype/leave_allocation/test_earned_leaves.py
Added two test methods for quarterly earned leave allocation scenarios at different points in the leave period. Modified helper function to accept an earned_leave_frequency parameter to enable testing different frequencies.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend (Leave Type Form)
    participant Backend (LeavePolicyAssignment)
    participant DB

    User->>Frontend (Leave Type Form): Select "earned_leave_frequency"
    Frontend (Leave Type Form)->>Frontend (Leave Type Form): Update "allocate_on_day" options

    User->>Backend (LeavePolicyAssignment): Trigger leave allocation
    Backend (LeavePolicyAssignment)->>Backend (LeavePolicyAssignment): Check "earned_leave_frequency"
    alt Monthly
        Backend (LeavePolicyAssignment)->>Backend (LeavePolicyAssignment): Call get_leaves_for_passed_months
    else Quarterly
        Backend (LeavePolicyAssignment)->>Backend (LeavePolicyAssignment): Call get_leaves_for_passed_quarters
    end
    Backend (LeavePolicyAssignment)->>DB: Update leave allocation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Leaves fall in quarters neat,
Rabbits dance with nimble feet.
Forms adapt and logic flows,
Quarterly growth now proudly shows.
Tests confirm the leaves accrue,
Monthly or quarterly too! 🌿✨

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 f18c171 and 1f928b8.

📒 Files selected for processing (1)
  • hrms/hr/doctype/leave_policy_assignment/leave_policy_assignment.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hrms/hr/doctype/leave_policy_assignment/leave_policy_assignment.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). (3)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Summary
✨ 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.
  • 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.

Support

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

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.

@asmitahase asmitahase force-pushed the fix-quarterly-leaves branch from c8abe13 to 0987fbe Compare August 4, 2025 04:33
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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8abe13 and 0987fbe.

📒 Files selected for processing (3)
  • hrms/hr/doctype/leave_allocation/test_earned_leaves.py (2 hunks)
  • hrms/hr/doctype/leave_policy_assignment/leave_policy_assignment.py (6 hunks)
  • hrms/hr/doctype/leave_type/leave_type.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • hrms/hr/doctype/leave_type/leave_type.js
  • hrms/hr/doctype/leave_allocation/test_earned_leaves.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). (3)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Summary
🔇 Additional comments (3)
hrms/hr/doctype/leave_policy_assignment/leave_policy_assignment.py (3)

12-12: LGTM! Import changes support quarterly calculations.

The new imports for quarter-related utilities (get_quarter_ending, get_quarter_start, month_diff, add_to_date) are correctly added and necessary for the quarterly earned leave functionality.

Also applies to: 21-24


249-258: LGTM! Clean refactoring of date calculation logic.

The extraction of the date calculation logic into a reusable public method is well done. The logic correctly handles edge cases and maintains the original functionality while enabling reuse in both monthly and quarterly calculations.


320-328: Omission of “Date of Joining” Is Intentional for Quarterly Frequency

The frontend form’s earned_leave_frequency handler limits allocate_on_day to only “First Day” and “Last Day” whenever the frequency is not “Monthly,” so excluding the “Date of Joining” branch from is_earned_leave_applicable_for_current_quarter aligns with the UI behavior and requires no further changes.

@asmitahase asmitahase force-pushed the fix-quarterly-leaves branch from 315a91e to 27e5f2d Compare August 4, 2025 05:17
@asmitahase asmitahase changed the title fix: allcate correct quarterly earned leaves fix: allocate correct quarterly earned leaves Aug 4, 2025
@asmitahase asmitahase force-pushed the fix-quarterly-leaves branch from 2c8e1f8 to 1f928b8 Compare August 4, 2025 07:16
@asmitahase
Copy link
Collaborator Author

Why are so many unrelated tests failing

@asmitahase
Copy link
Collaborator Author

asmitahase commented Aug 4, 2025

Similar tests failing over at eprnext too with frappe/erpnext#48561
https://github.com/frappe/erpnext/actions/runs/16641775844/job/47302305887?pr=48561
Related?

@ljain112
Copy link

ljain112 commented Aug 4, 2025

@asmitahase

Recently changes made to advance doctypes handling in payment reference.
Now Advance Doctype reference is not being set in GL ENTRY.

check PR: frappe/erpnext#48341

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.

2 participants