From 62011c9dc40f46cde0b3395452168e5077ba44c9 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Wed, 5 Jun 2019 21:16:27 +0530 Subject: [PATCH] feat: add link to policy --- .../leave_allocation/leave_allocation.js | 13 +++++-- .../leave_allocation/leave_allocation.json | 35 ++++++++++++++++++- .../leave_allocation/leave_allocation.py | 6 ++-- .../leave_policy/leave_policy_dashboard.py | 5 ++- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js index 489db67109..50dbaadec7 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js @@ -22,10 +22,19 @@ frappe.ui.form.on("Leave Allocation", { }, refresh: function(frm) { - if(frm.doc.docstatus == 1){ - frm.add_custom_button('Expire Allocation', function() { + if(frm.doc.docstatus === 1 && frm.doc.status === "Active") { + // expire current allocation + frm.add_custom_button(__('Expire Allocation'), function() { frm.trigger("expire_allocation"); }); + + // opens leave balance report for employee + frm.add_custom_button(__('Check Leave Balance'), function() { + frappe.route_options = { + employee: frm.doc.employee, + }; + frappe.set_route("query-report", "Employee Leave Balance"); + }); } }, diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json index 1d6307cbe1..125fb3150b 100644 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json @@ -599,6 +599,39 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "status", + "fieldtype": "Select", + "hidden": 1, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 1, + "label": "Status", + "length": 0, + "no_copy": 0, + "options": "Active\nExpired", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_in_quick_entry": 0, @@ -711,7 +744,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2019-05-30 11:28:09.360525", + "modified": "2019-05-31 11:28:09.360525", "modified_by": "Administrator", "module": "HR", "name": "Leave Allocation", diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index 0b2972e565..b402e908b0 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -183,13 +183,15 @@ def expire_current_allocation(ref_doc): if flt(leaves) > 0: args = dict( leaves=leaves * -1, - from_date=ref_doc.from_date, - to_date=ref_doc.from_date, + from_date=ref_doc.to_date, + to_date=ref_doc.to_date, is_carry_forward=0, is_expired=1 ) create_leave_ledger_entry(ref_doc, args) + frappe.db.set_value("Leave Allocation", ref_doc.name, "status", "Expired") + def get_unused_leaves(employee, leave_type, date): return frappe.db.get_value("Leave Ledger Entry", filters={ "to_date": ("<=", date), diff --git a/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py b/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py index f97d2855a4..48a204596c 100644 --- a/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py +++ b/erpnext/hr/doctype/leave_policy/leave_policy_dashboard.py @@ -12,6 +12,9 @@ def get_data(): }, { 'items': ['Employee Grade'] - } + }, + { + 'items': ['Leave Allocation'] + }, ] } \ No newline at end of file