From ffec9516fac7855107a86fed2a6acca6c44bd39f Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 25 Mar 2022 20:11:38 +0530 Subject: [PATCH] fix: do not update status to Paid if sanctioned amount is 0 --- erpnext/hr/doctype/expense_claim/expense_claim.py | 10 ++++++---- erpnext/hr/doctype/expense_claim/test_expense_claim.py | 9 +++++++++ .../update_expense_claim_status_for_paid_advances.py | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 9bb31b3ad83..12a31123966 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -47,10 +47,12 @@ class ExpenseClaim(AccountsController): 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 285717a68d1..1244cc43642 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 @@ class TestExpenseClaim(unittest.TestCase): 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 206d032f534..063de1637d0 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 @@ def execute(): .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()