From 8333b5754b6324d3bd36c2b7d4d78043db467aa7 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 17 Jul 2017 15:56:36 +0530 Subject: [PATCH] [Fix] Expense claim status issue --- .../doctype/journal_entry/journal_entry.js | 9 +++++++- .../doctype/expense_claim/expense_claim.json | 4 ++-- .../hr/doctype/expense_claim/expense_claim.py | 10 ++++++-- .../expense_claim/expense_claim_list.js | 4 +++- erpnext/patches.txt | 3 ++- .../v8_1/update_expense_claim_status.py | 23 +++++++++++++++++++ 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 erpnext/patches/v8_1/update_expense_claim_status.py diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 4880224c24..ba4cc83a4a 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -96,7 +96,14 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({ // 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 48dcfbbaf5..5708c047f1 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 1cd725734f..2781f28213 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -39,10 +39,13 @@ class ExpenseClaim(AccountsController): "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 @@ class ExpenseClaim(AccountsController): 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 7cff8e2f21..f5a6f4cca3 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 @@ frappe.listview_settings['Expense Claim'] = { 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 16c5a8713e..af0afdb4d9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -418,4 +418,5 @@ erpnext.patches.v8_1.allow_invoice_copy_to_edit_after_submit 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 0000000000..4c1b85a13f --- /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