chore: split expire allocation

This commit is contained in:
Mangesh-Khairnar 2019-07-22 18:05:27 +05:30
parent 08c02287dd
commit fd1d4c2927
5 changed files with 40 additions and 25 deletions

View File

@ -22,7 +22,7 @@ frappe.ui.form.on("Leave Allocation", {
},
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 @@ frappe.ui.form.on("Leave Allocation", {
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){

View File

@ -24,7 +24,7 @@
"compensatory_request",
"leave_period",
"leave_policy",
"status",
"expired",
"amended_from",
"notes",
"description"
@ -167,15 +167,6 @@
"options": "Leave Policy",
"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",
@ -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",

View File

@ -42,7 +42,7 @@ class LeaveAllocation(Document):
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 @@ class LeaveAllocation(Document):
)
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 @@ class LeaveAllocation(Document):
)
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",

View File

@ -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"];
}
},
};

View File

@ -54,7 +54,7 @@ def generate_expiry_allocation_ledger_entries():
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("""