feat: expire current allocation
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js
index 1fc1d89..489db67 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js
@@ -21,6 +21,29 @@
 		})
 	},
 
+	refresh: function(frm) {
+		if(frm.doc.docstatus == 1){
+			frm.add_custom_button('Expire Allocation', function() {
+				frm.trigger("expire_allocation");
+			});
+		}
+	},
+
+	expire_allocation: function(frm) {
+		frappe.call({
+			method: 'erpnext.hr.doctype.leave_application.leave_application.expire_previous_allocation',
+			args: {
+				ref_doc: frm.doc
+			},
+			freeze: true,
+			callback: function(r){
+				if(!r.exc){
+					frappe.msgprint(__("Allocation Expired!"));
+				}
+			}
+		});
+	},
+
 	employee: function(frm) {
 		frm.trigger("calculate_total_leaves_allocated");
 	},
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
index 568182d..1d6307c 100644
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
@@ -572,6 +572,40 @@
    "bold": 0,
    "collapsible": 0,
    "columns": 0,
+   "fetch_from": "employee.leave_policy",
+   "fieldname": "leave_policy",
+   "fieldtype": "Link",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 1,
+   "label": "Leave Policy",
+   "length": 0,
+   "no_copy": 0,
+   "options": "Leave Policy",
+   "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,
+   "allow_on_submit": 0,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
    "fieldname": "amended_from",
    "fieldtype": "Link",
    "hidden": 0,
@@ -677,7 +711,7 @@
  "issingle": 0,
  "istable": 0,
  "max_attachments": 0,
- "modified": "2019-05-22 11:28:09.360525",
+ "modified": "2019-05-30 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 2a1301d..0b2972e 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
@@ -131,7 +131,7 @@
 
 	def expire_previous_allocation(self):
 		''' expire previous allocation leaves '''
-		leaves = get_remaining_leaves(self.employee, self.leave_type, self.from_date)
+		leaves = get_unused_leaves(self.employee, self.leave_type, self.from_date)
 
 		if flt(leaves) > 0:
 			args = dict(
@@ -171,11 +171,26 @@
 	carry_forwarded_leaves = 0
 	if carry_forward:
 		validate_carry_forward(leave_type)
-		carry_forwarded_leaves = get_remaining_leaves(employee, leave_type, date)
+		carry_forwarded_leaves = get_unused_leaves(employee, leave_type, date)
 
 	return carry_forwarded_leaves
 
-def get_remaining_leaves(employee, leave_type, date):
+@frappe.whitelist()
+def expire_current_allocation(ref_doc):
+		''' expire previous allocation leaves '''
+		leaves = get_unused_leaves(ref_doc.employee, ref_doc.leave_type, ref_doc.to_date)
+
+		if flt(leaves) > 0:
+			args = dict(
+				leaves=leaves * -1,
+				from_date=ref_doc.from_date,
+				to_date=ref_doc.from_date,
+				is_carry_forward=0,
+				is_expired=1
+			)
+			create_leave_ledger_entry(ref_doc, args)
+
+def get_unused_leaves(employee, leave_type, date):
 	return frappe.db.get_value("Leave Ledger Entry", filters={
 			"to_date": ("<=", date),
 			"employee": employee,