chore: split expire allocation
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js
index 2a26a85..7c3e1e4 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js
@@ -22,7 +22,7 @@
},
refresh: function(frm) {
- if(frm.doc.docstatus === 1 && frm.doc.status === "Active") {
+ if(frm.doc.docstatus === 1 && frm.doc.expired) {
var valid_expiry = moment(frappe.datetime.get_today()).isBetween(frm.doc.from_date, frm.doc.to_date);
if(valid_expiry) {
// expire current allocation
@@ -35,11 +35,8 @@
expire_allocation: function(frm) {
frappe.call({
- method: 'expire_allocation',
+ method: 'expire_current_allocation',
doc: frm.doc,
- args: {
- current: true
- },
freeze: true,
callback: function(r){
if(!r.exc){
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
index 41d864d..1618c67 100644
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
@@ -24,7 +24,7 @@
"compensatory_request",
"leave_period",
"leave_policy",
- "status",
+ "expired",
"amended_from",
"notes",
"description"
@@ -168,15 +168,6 @@
"read_only": 1
},
{
- "fieldname": "status",
- "fieldtype": "Select",
- "hidden": 1,
- "in_standard_filter": 1,
- "label": "Status",
- "options": "Active\nExpired",
- "read_only": 1
- },
- {
"fieldname": "amended_from",
"fieldtype": "Link",
"ignore_user_permissions": 1,
@@ -201,12 +192,21 @@
"oldfieldname": "reason",
"oldfieldtype": "Small Text",
"width": "300px"
+ },
+ {
+ "default": "0",
+ "fieldname": "expired",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "in_standard_filter": 1,
+ "label": "Expired",
+ "read_only": 1
}
],
"icon": "fa fa-ok",
"idx": 1,
"is_submittable": 1,
- "modified": "2019-06-14 15:39:02.898695",
+ "modified": "2019-07-22 17:50:39.591195",
"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 df479e7..494043f 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
@@ -42,7 +42,7 @@
def on_submit(self):
self.create_leave_ledger_entry()
- self.expire_allocation()
+ self.expire_previous_allocation()
def on_cancel(self):
self.create_leave_ledger_entry(submit=False)
@@ -128,14 +128,14 @@
)
create_leave_ledger_entry(self, args, submit)
- def expire_allocation(self, current=False):
+ def expire_current_allocation(self):
''' expires allocation '''
- date = self.to_date if current else self.from_date
+ date = self.to_date
leaves = get_unused_leaves(self.employee, self.leave_type, date)
- ref_name = self.name if current else self.get_previous_allocation()
+ ref_name = self.name
if leaves:
- expiry_date = today() if current else add_days(self.from_date, -1)
+ expiry_date = today()
args = dict(
leaves=flt(leaves) * -1,
transaction_name=ref_name,
@@ -146,8 +146,26 @@
)
create_leave_ledger_entry(self, args)
- if current:
- frappe.db.set_value("Leave Allocation", self.name, "status", "Expired")
+ frappe.db.set_value("Leave Allocation", self.name, "expired", 1)
+
+ def expire_previous_allocation(self):
+ date = self.from_date
+ leaves = get_unused_leaves(self.employee, self.leave_type, date)
+ ref_name = self.get_previous_allocation()
+
+ if leaves:
+ expiry_date = add_days(self.from_date, -1)
+ args = dict(
+ leaves=flt(leaves) * -1,
+ transaction_name=ref_name,
+ from_date=expiry_date,
+ to_date=expiry_date,
+ is_carry_forward=0,
+ is_expired=1
+ )
+ create_leave_ledger_entry(self, args)
+
+ frappe.db.set_value("Leave Allocation", ref_name, "expired", 1)
def get_previous_allocation(self):
return frappe.db.get_value("Leave Allocation",
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation_list.js b/erpnext/hr/doctype/leave_allocation/leave_allocation_list.js
index 3ea0e24..93f7b83 100644
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation_list.js
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation_list.js
@@ -5,7 +5,7 @@
frappe.listview_settings['Leave Allocation'] = {
get_indicator: function(doc) {
if(doc.status==="Expired") {
- return [__("Expired"), "darkgrey", "status, =, Expired"];
+ return [__("Expired"), "darkgrey", "expired, =, 1"];
}
},
};
diff --git a/erpnext/patches/v12_0/generate_leave_ledger_entries.py b/erpnext/patches/v12_0/generate_leave_ledger_entries.py
index 8a92bb3..f2a798e 100644
--- a/erpnext/patches/v12_0/generate_leave_ledger_entries.py
+++ b/erpnext/patches/v12_0/generate_leave_ledger_entries.py
@@ -54,7 +54,7 @@
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Allocation', 'transaction_name': allocation.name, 'is_expired': 1}):
allocation.update(dict(doctype="Leave Allocation"))
allocation_obj = frappe.get_doc(allocation)
- allocation_obj.expire_allocation()
+ allocation_obj.expire_previous_allocation()
def get_allocation_records():
return frappe.db.sql("""