Skip to content

fix(expense_claim): handle partial advance settlement in expense claims#4563

Open
iamkhanraheel wants to merge 2 commits into
frappe:developfrom
iamkhanraheel:fix/expense_claim_outstanding_payment
Open

fix(expense_claim): handle partial advance settlement in expense claims#4563
iamkhanraheel wants to merge 2 commits into
frappe:developfrom
iamkhanraheel:fix/expense_claim_outstanding_payment

Conversation

@iamkhanraheel
Copy link
Copy Markdown
Collaborator

@iamkhanraheel iamkhanraheel commented May 20, 2026

Reason

  • Expense Claims created from Employee Advance were incorrectly marked as "Paid" even when the advance amount only partially covered the claimed amount. As a result outstanding payable amount was ignored and payment action was not available
claimReimburseBug.mov

Changes Done

  • Expense Claims with partial Employee Advance coverage are now correctly marked as “Unpaid” instead of “Paid”, ensuring any remaining balance is available for reimbursement flow.
claimReimburseFix.mov

Summary by CodeRabbit

  • Bug Fixes

    • Expense claim status logic corrected so claims with advances aren’t prematurely marked as paid when advances remain unsettled.
  • Tests

    • Updated expense claim tests to cover advance-linked scenarios and verify is_paid behavior before and after submission.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4f86250-a986-4847-85d3-aebb27be540f

📥 Commits

Reviewing files that changed from the base of the PR and between 47ee858 and 39ce693.

📒 Files selected for processing (1)
  • hrms/hr/doctype/expense_claim/test_expense_claim.py

Walkthrough

This PR adds a validation rule in the ExpenseClaim.validate method that resets is_paid to 0 when a claim has a positive grand_total and an associated total_advance_amount. The change runs before set_status() is called, affecting how the claim's status is subsequently calculated. This prevents the status from incorrectly resolving to "Paid" in scenarios where advances exist but the claim settlement is incomplete.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'fix(expense_claim): handle partial advance settlement in expense claims' directly and clearly summarizes the main change: handling partial advance settlement in expense claims, which aligns with the core fix described in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
hrms/hr/doctype/expense_claim/expense_claim.py (1)

114-120: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Move is_paid reset before set_status() to make the fix effective.

Right now, self.set_status() (Line 114) runs before self.is_paid = 0 (Line 120), so status can still be computed as "Paid" using stale is_paid. This defeats the intended partial-advance behavior.

Suggested fix
 		self.calculate_taxes()
-		self.set_status()
+		if flt(self.grand_total) > 0 and self.total_advance_amount:
+			self.is_paid = 0
+		self.set_status()
 		self.validate_company_and_department()
 		if self.task and not self.project:
 			self.project = frappe.db.get_value("Task", self.task, "project")
-
-		if flt(self.grand_total) > 0 and self.total_advance_amount:
-			self.is_paid = 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/expense_claim/expense_claim.py` around lines 114 - 120, Move
the is_paid reset so it runs before status calculation: ensure that self.is_paid
is set to 0 (when flt(self.grand_total) > 0 and self.total_advance_amount) prior
to calling self.set_status(); update the order in the method so self.is_paid
assignment occurs before the call to set_status(), keeping the existing project
lookup (self.project = frappe.db.get_value("Task", self.task, "project")) and
validate_company_and_department() in their current logical places.
🤖 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.

Outside diff comments:
In `@hrms/hr/doctype/expense_claim/expense_claim.py`:
- Around line 114-120: Move the is_paid reset so it runs before status
calculation: ensure that self.is_paid is set to 0 (when flt(self.grand_total) >
0 and self.total_advance_amount) prior to calling self.set_status(); update the
order in the method so self.is_paid assignment occurs before the call to
set_status(), keeping the existing project lookup (self.project =
frappe.db.get_value("Task", self.task, "project")) and
validate_company_and_department() in their current logical places.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3bb19a2f-4656-4f60-9278-32f4c6483eb6

📥 Commits

Reviewing files that changed from the base of the PR and between 5587174 and 47ee858.

📒 Files selected for processing (1)
  • hrms/hr/doctype/expense_claim/expense_claim.py

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