[Fix] Expense claim status issue
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 4880224..ba4cc83 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -96,7 +96,14 @@
// expense claim
if(jvd.reference_type==="Expense Claim") {
- return {};
+ return {
+ filters: {
+ 'approval_status': 'Approved',
+ 'total_sanctioned_amount': ['>', 0],
+ 'status': ['!=', 'Paid'],
+ 'docstatus': 1
+ }
+ };
}
// journal entry
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json
index 48dcfbb..5708c04 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.json
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.json
@@ -905,7 +905,7 @@
"label": "Status",
"length": 0,
"no_copy": 1,
- "options": "Draft\nPaid\nUnpaid\nSubmitted\nCancelled",
+ "options": "Draft\nPaid\nUnpaid\nRejected\nSubmitted\nCancelled",
"permlevel": 0,
"precision": "",
"print_hide": 1,
@@ -964,7 +964,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
- "modified": "2017-06-13 14:29:16.914609",
+ "modified": "2017-07-17 15:47:23.255142",
"modified_by": "Administrator",
"module": "HR",
"name": "Expense Claim",
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index 1cd7257..2781f28 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -39,10 +39,13 @@
"2": "Cancelled"
}[cstr(self.docstatus or 0)]
- if self.total_sanctioned_amount == self.total_amount_reimbursed and self.docstatus == 1:
+ if self.total_sanctioned_amount > 0 and self.total_sanctioned_amount == self.total_amount_reimbursed \
+ and self.docstatus == 1 and self.approval_status == 'Approved':
self.status = "Paid"
- elif self.docstatus == 1:
+ elif self.total_sanctioned_amount > 0 and self.docstatus == 1 and self.approval_status == 'Approved':
self.status = "Unpaid"
+ elif self.docstatus == 1 and self.approval_status == 'Rejected':
+ self.status = 'Rejected'
def set_payable_account(self):
if not self.payable_account and not self.is_paid:
@@ -157,6 +160,9 @@
self.total_claimed_amount = 0
self.total_sanctioned_amount = 0
for d in self.get('expenses'):
+ if self.approval_status == 'Rejected':
+ d.sanctioned_amount = 0.0
+
self.total_claimed_amount += flt(d.claim_amount)
self.total_sanctioned_amount += flt(d.sanctioned_amount)
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim_list.js b/erpnext/hr/doctype/expense_claim/expense_claim_list.js
index 7cff8e2..f5a6f4c 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim_list.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim_list.js
@@ -4,8 +4,10 @@
get_indicator: function(doc) {
if(doc.status == "Paid") {
return [__("Paid"), "green", "status,=,'Paid'"];
- } else {
+ }else if(doc.status == "Unpaid") {
return [__("Unpaid"), "orange"];
+ } else if(doc.status == "Rejected") {
+ return [__("Rejected"), "grey"];
}
}
};
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 16c5a87..af0afdb 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -418,4 +418,5 @@
erpnext.patches.v8_1.add_hsn_sac_codes
erpnext.patches.v8_1.update_gst_state #17-07-2017
erpnext.patches.v8_1.removed_report_support_hours
-erpnext.patches.v8_1.add_indexes_in_transaction_doctypes
\ No newline at end of file
+erpnext.patches.v8_1.add_indexes_in_transaction_doctypes
+erpnext.patches.v8_1.update_expense_claim_status
\ No newline at end of file
diff --git a/erpnext/patches/v8_1/update_expense_claim_status.py b/erpnext/patches/v8_1/update_expense_claim_status.py
new file mode 100644
index 0000000..4c1b85a
--- /dev/null
+++ b/erpnext/patches/v8_1/update_expense_claim_status.py
@@ -0,0 +1,23 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doctype('Expense Claim')
+
+ for data in frappe.db.sql(""" select name from `tabExpense Claim`
+ where (docstatus=1 and total_sanctioned_amount=0 and status = 'Paid') or
+ (docstatus = 1 and approval_status = 'Rejected' and total_sanctioned_amount > 0)""", as_dict=1):
+ doc = frappe.get_doc('Expense Claim', data.name)
+ if doc.approval_status == 'Rejected':
+ for d in doc.expenses:
+ d.db_set("sanctioned_amount", 0, update_modified = False)
+ doc.db_set("total_sanctioned_amount", 0, update_modified = False)
+
+ frappe.db.sql(""" delete from `tabGL Entry` where voucher_type = 'Expense Claim'
+ and voucher_no = %s""", (doc.name))
+
+ doc.set_status()
+ doc.db_set("status", doc.status, update_modified = False)
\ No newline at end of file