fix: do not update status to Paid if sanctioned amount is 0
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index 9bb31b3..12a3112 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -47,10 +47,12 @@
if (
# set as paid
self.is_paid
- # grand total is reimbursed
- or (flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 and flt(self.grand_total, precision) == flt(self.total_amount_reimbursed, precision))
- # grand total (to be paid) is 0 since linked advances already cover the claimed amount
- or (flt(self.grand_total, precision) == 0)
+ or (flt(self.total_sanctioned_amount > 0) and (
+ # grand total is reimbursed
+ (self.docstatus == 1 and flt(self.grand_total, precision) == flt(self.total_amount_reimbursed, precision))
+ # grand total (to be paid) is 0 since linked advances already cover the claimed amount
+ or (flt(self.grand_total, precision) == 0)
+ ))
) and self.approval_status == "Approved":
status = "Paid"
elif flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 and self.approval_status == 'Approved':
diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
index 285717a..1244cc4 100644
--- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
@@ -72,6 +72,15 @@
expense_claim = frappe.get_doc("Expense Claim", expense_claim.name)
self.assertEqual(expense_claim.status, "Unpaid")
+ # expense claim without any sanctioned amount should not have status as Paid
+ claim = make_expense_claim(payable_account, 1000, 0, "_Test Company", "Travel Expenses - _TC")
+ self.assertEqual(claim.total_sanctioned_amount, 0)
+ self.assertEqual(claim.status, "Submitted")
+
+ # no gl entries created
+ gl_entry = frappe.get_all('GL Entry', {'voucher_type': 'Expense Claim', 'voucher_no': claim.name})
+ self.assertEqual(len(gl_entry), 0)
+
def test_expense_claim_against_fully_paid_advances(self):
from erpnext.hr.doctype.employee_advance.test_employee_advance import (
get_advances_for_claim,
diff --git a/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py b/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py
index 206d032..063de16 100644
--- a/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py
+++ b/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py
@@ -16,6 +16,7 @@
.where(
((ExpenseClaim.grand_total == 0) | (ExpenseClaim.grand_total == ExpenseClaim.total_amount_reimbursed))
& (ExpenseClaim.approval_status == 'Approved')
- & (ExpenseClaim.docstatus != 2)
+ & (ExpenseClaim.docstatus == 1)
+ & (ExpenseClaim.total_sanctioned_amount > 0)
)
).run()