Skip to content

fix: update expense claim outstanding amount and status on payment unreconcile #3421

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

Conversation

sumitjain236
Copy link

@sumitjain236 sumitjain236 commented Jul 31, 2025

Description

This PR fixes an issue where Expense Claims were not updating their outstanding amount and status when a Payment Entry linked to the claim was unreconciled.

Issue:

  • When an Expense Claim is submitted, users can create a Payment Entry to reimburse the employee.
  • On Payment Entry submission, the Expense Claim gets its outstanding amount and status updated correctly.
  • However, if the Payment Entry is unreconciled, the Expense Claim was not updating, leaving incorrect outstanding amounts and status.

Solution Implemented:

  • Added a new handler: update_expense_claim_on_unreconcile_payment
  • On unreconcile payment submission:
  1. Loop through allocations in the Unreconcile Payment.
  2. Check if the allocation is linked to an Expense Claim.
  3. Fetch the related Expense Claim document.
  4. Call update_reimbursed_amount() to recalculate outstanding amount and update status.

This ensures that Expense Claims now remain accurate.

Testing

  1. Create an Expense Claim and submit it.
  2. Create a Payment Entry against the Expense Claim and submit.
  3. Confirm that the outstanding amount and status update correctly.
  4. Unreconcile the Payment Entry.
  5. Verify that the Expense Claim outstanding amount and status update correctly.

Summary by CodeRabbit

  • New Features
    • Expense Claims are now automatically updated when an Unreconcile Payment is submitted, ensuring the reimbursed amount and status reflect recent changes.

Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

A new document event hook was introduced for the "Unreconcile Payment" doctype, triggering an update function on submit. The added function updates the reimbursed amount of related Expense Claims when an unreconcile payment is processed, ensuring accurate tracking of reimbursement status.

Changes

Cohort / File(s) Change Summary
Document Event Hook Addition
hrms/hooks.py
Registered an "on_submit" event for "Unreconcile Payment", linking it to a new update function.
Expense Claim Update Logic
hrms/hr/doctype/expense_claim/expense_claim.py
Added update_expense_claim_on_unreconcile_payment to update Expense Claim reimbursement data when an unreconcile payment is submitted.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ERP System
    participant UnreconcilePaymentDoc
    participant ExpenseClaimDoc

    User->>ERP System: Submit Unreconcile Payment
    ERP System->>UnreconcilePaymentDoc: on_submit event triggered
    UnreconcilePaymentDoc->>ERP System: Call update_expense_claim_on_unreconcile_payment
    ERP System->>ExpenseClaimDoc: For each allocation referencing Expense Claim, fetch and update
    ExpenseClaimDoc->>ERP System: update_reimbursed_amount called
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A hook now hops on payment’s trail,
Updating claims without fail.
When unreconcile is set anew,
Expense Claims get their timely review.
Rabbits rejoice—no more mismatch,
Every carrot, every batch!
🥕✨

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 be497bc and 95754c2.

📒 Files selected for processing (2)
  • hrms/hooks.py (1 hunks)
  • hrms/hr/doctype/expense_claim/expense_claim.py (1 hunks)
⏰ 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
🔇 Additional comments (2)
hrms/hr/doctype/expense_claim/expense_claim.py (1)

654-666: LGTM! Clean implementation following existing patterns.

The function correctly handles the unreconcile payment scenario by:

  • Processing each allocation in the unreconcile payment document
  • Filtering for Expense Claim references
  • Reusing the existing update_reimbursed_amount function for consistency

The implementation follows the same pattern as update_payment_for_expense_claim and integrates well with the existing codebase.

hrms/hooks.py (1)

212-214: LGTM! Proper event hook registration.

The document event hook is correctly configured:

  • Uses "on_submit" event which is appropriate for updating Expense Claims when unreconcile payment is submitted
  • Function path correctly references the implementation in expense_claim.py
  • Follows the existing pattern used for other document events in the file
✨ 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.

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