[enhacement] remove fiscal year from leave allocation
This commit is contained in:
parent
32e48bb568
commit
d0b0a80be3
@ -147,22 +147,20 @@
|
|||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"default": "Today",
|
"fieldname": "from_date",
|
||||||
"fieldname": "posting_date",
|
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_list_view": 1,
|
"in_list_view": 0,
|
||||||
"label": "Posting Date",
|
"label": "From Date",
|
||||||
"no_copy": 1,
|
"no_copy": 0,
|
||||||
"oldfieldname": "date",
|
|
||||||
"oldfieldtype": "Date",
|
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"read_only": 1,
|
"read_only": 0,
|
||||||
"report_hide": 0,
|
"report_hide": 0,
|
||||||
"reqd": 1,
|
"reqd": 0,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
@ -171,23 +169,21 @@
|
|||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"fieldname": "fiscal_year",
|
"fieldname": "to_date",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Date",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"in_filter": 1,
|
"in_filter": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
"label": "Fiscal Year",
|
"label": "To Date",
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"oldfieldname": "fiscal_year",
|
|
||||||
"oldfieldtype": "Data",
|
|
||||||
"options": "Fiscal Year",
|
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
"report_hide": 0,
|
"report_hide": 0,
|
||||||
"reqd": 1,
|
"reqd": 0,
|
||||||
"search_index": 1,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
@ -310,7 +306,7 @@
|
|||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-10-02 07:38:55.314632",
|
"modified": "2015-10-28 14:52:26.724671",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Leave Allocation",
|
"name": "Leave Allocation",
|
||||||
@ -359,7 +355,7 @@
|
|||||||
],
|
],
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
"read_only_onload": 0,
|
"read_only_onload": 0,
|
||||||
"search_fields": "employee,employee_name,leave_type,total_leaves_allocated,fiscal_year",
|
"search_fields": "employee,employee_name,leave_type,total_leaves_allocated",
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC"
|
"sort_order": "DESC"
|
||||||
}
|
}
|
@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import cint, flt
|
from frappe.utils import cint, flt, date_diff
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from erpnext.hr.utils import set_employee_name
|
from erpnext.hr.utils import set_employee_name
|
||||||
|
|
||||||
class LeaveAllocation(Document):
|
class LeaveAllocation(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_period()
|
||||||
self.validate_new_leaves_allocated_value()
|
self.validate_new_leaves_allocated_value()
|
||||||
self.check_existing_leave_allocation()
|
self.check_existing_leave_allocation()
|
||||||
if not self.total_leaves_allocated:
|
if not self.total_leaves_allocated:
|
||||||
@ -21,8 +22,13 @@ class LeaveAllocation(Document):
|
|||||||
self.validate_new_leaves_allocated_value()
|
self.validate_new_leaves_allocated_value()
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
|
pass
|
||||||
self.get_total_allocated_leaves()
|
self.get_total_allocated_leaves()
|
||||||
|
|
||||||
|
def validate_period(self):
|
||||||
|
if date_diff(self.to_date, self.from_date) <= 0:
|
||||||
|
frappe.throw(_("Invalid period"))
|
||||||
|
|
||||||
def validate_new_leaves_allocated_value(self):
|
def validate_new_leaves_allocated_value(self):
|
||||||
"""validate that leave allocation is in multiples of 0.5"""
|
"""validate that leave allocation is in multiples of 0.5"""
|
||||||
if flt(self.new_leaves_allocated) % 0.5:
|
if flt(self.new_leaves_allocated) % 0.5:
|
||||||
@ -30,29 +36,30 @@ class LeaveAllocation(Document):
|
|||||||
|
|
||||||
def check_existing_leave_allocation(self):
|
def check_existing_leave_allocation(self):
|
||||||
"""check whether leave for same type is already allocated or not"""
|
"""check whether leave for same type is already allocated or not"""
|
||||||
leave_allocation = frappe.db.sql("""select name from `tabLeave Allocation`
|
leave_allocation = frappe.db.sql("""select name from `tabLeave Allocation`
|
||||||
where employee=%s and leave_type=%s and fiscal_year=%s and docstatus=1""",
|
where employee='%s' and leave_type='%s' and to_date >= '%s' and from_date <= '%s' and docstatus=1
|
||||||
(self.employee, self.leave_type, self.fiscal_year))
|
"""%(self.employee, self.leave_type, self.from_date, self.to_date))
|
||||||
|
|
||||||
if leave_allocation:
|
if leave_allocation:
|
||||||
frappe.msgprint(_("Leaves for type {0} already allocated for Employee {1} for Fiscal Year {0}").format(self.leave_type,
|
frappe.msgprint(_("Leaves for type {0} already allocated for Employee {1} for period {2} - {3}").format(self.leave_type,
|
||||||
self.employee, self.fiscal_year))
|
self.employee, self.from_date, self.to_date))
|
||||||
frappe.throw('<a href="#Form/Leave Allocation/{0}">{0}</a>'.format(leave_allocation[0][0]))
|
frappe.throw('<a href="#Form/Leave Allocation/{0}">{0}</a>'.format(leave_allocation[0][0]))
|
||||||
|
|
||||||
def get_leave_bal(self, prev_fyear):
|
def get_leave_bal(self):
|
||||||
return self.get_leaves_allocated(prev_fyear) - self.get_leaves_applied(prev_fyear)
|
return self.get_leaves_allocated() - self.get_leaves_applied()
|
||||||
|
|
||||||
def get_leaves_applied(self, fiscal_year):
|
def get_leaves_applied(self):
|
||||||
leaves_applied = frappe.db.sql("""select SUM(ifnull(total_leave_days, 0))
|
leaves_applied = frappe.db.sql("""select SUM(ifnull(total_leave_days, 0))
|
||||||
from `tabLeave Application` where employee=%s and leave_type=%s
|
from `tabLeave Application` where employee=%s and leave_type=%s
|
||||||
and fiscal_year=%s and docstatus=1""",
|
and to_date<=%s and docstatus=1""",
|
||||||
(self.employee, self.leave_type, fiscal_year))
|
(self.employee, self.leave_type, self.from_date))
|
||||||
return leaves_applied and flt(leaves_applied[0][0]) or 0
|
return leaves_applied and flt(leaves_applied[0][0]) or 0
|
||||||
|
|
||||||
def get_leaves_allocated(self, fiscal_year):
|
def get_leaves_allocated(self):
|
||||||
leaves_allocated = frappe.db.sql("""select SUM(ifnull(total_leaves_allocated, 0))
|
leaves_allocated = frappe.db.sql("""select SUM(ifnull(total_leaves_allocated, 0))
|
||||||
from `tabLeave Allocation` where employee=%s and leave_type=%s
|
from `tabLeave Allocation` where employee=%s and leave_type=%s
|
||||||
and fiscal_year=%s and docstatus=1 and name!=%s""",
|
and to_date<=%s and docstatus=1 and name!=%s""",
|
||||||
(self.employee, self.leave_type, fiscal_year, self.name))
|
(self.employee, self.leave_type, self.from_date, self.name))
|
||||||
return leaves_allocated and flt(leaves_allocated[0][0]) or 0
|
return leaves_allocated and flt(leaves_allocated[0][0]) or 0
|
||||||
|
|
||||||
def allow_carry_forward(self):
|
def allow_carry_forward(self):
|
||||||
@ -67,14 +74,11 @@ class LeaveAllocation(Document):
|
|||||||
def get_carry_forwarded_leaves(self):
|
def get_carry_forwarded_leaves(self):
|
||||||
if self.carry_forward:
|
if self.carry_forward:
|
||||||
self.allow_carry_forward()
|
self.allow_carry_forward()
|
||||||
prev_fiscal_year = frappe.db.sql("""select name from `tabFiscal Year`
|
|
||||||
where year_start_date = (select date_add(year_start_date, interval -1 year)
|
|
||||||
from `tabFiscal Year` where name=%s)
|
|
||||||
order by name desc limit 1""", self.fiscal_year)
|
|
||||||
prev_fiscal_year = prev_fiscal_year and prev_fiscal_year[0][0] or ''
|
|
||||||
prev_bal = 0
|
prev_bal = 0
|
||||||
if prev_fiscal_year and cint(self.carry_forward) == 1:
|
if cint(self.carry_forward) == 1:
|
||||||
prev_bal = self.get_leave_bal(prev_fiscal_year)
|
prev_bal = self.get_leave_bal()
|
||||||
|
|
||||||
ret = {
|
ret = {
|
||||||
'carry_forwarded_leaves': prev_bal,
|
'carry_forwarded_leaves': prev_bal,
|
||||||
'total_leaves_allocated': flt(prev_bal) + flt(self.new_leaves_allocated)
|
'total_leaves_allocated': flt(prev_bal) + flt(self.new_leaves_allocated)
|
||||||
|
@ -53,10 +53,6 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
frm.trigger("get_leave_balance");
|
frm.trigger("get_leave_balance");
|
||||||
},
|
},
|
||||||
|
|
||||||
fiscal_year: function(frm) {
|
|
||||||
frm.trigger("get_leave_balance");
|
|
||||||
},
|
|
||||||
|
|
||||||
leave_type: function(frm) {
|
leave_type: function(frm) {
|
||||||
frm.trigger("get_leave_balance");
|
frm.trigger("get_leave_balance");
|
||||||
},
|
},
|
||||||
@ -85,12 +81,13 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get_leave_balance: function(frm) {
|
get_leave_balance: function(frm) {
|
||||||
if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.fiscal_year) {
|
if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.from_date && frm.doc.to_date) {
|
||||||
return frm.call({
|
return frm.call({
|
||||||
method: "get_leave_balance",
|
method: "get_leave_balance",
|
||||||
args: {
|
args: {
|
||||||
employee: frm.doc.employee,
|
employee: frm.doc.employee,
|
||||||
fiscal_year: frm.doc.fiscal_year,
|
from_date: frm.doc.from_date,
|
||||||
|
to_date: frm.doc.to_date,
|
||||||
leave_type: frm.doc.leave_type
|
leave_type: frm.doc.leave_type
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -109,6 +106,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
callback: function(response) {
|
callback: function(response) {
|
||||||
if (response && response.message) {
|
if (response && response.message) {
|
||||||
frm.set_value('total_leave_days', response.message.total_leave_days);
|
frm.set_value('total_leave_days', response.message.total_leave_days);
|
||||||
|
frm.trigger("get_leave_balance");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
"label": "Status",
|
"label": "Status",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "Open\nApproved\nRejected",
|
"options": "Open\nApproved\nRejected",
|
||||||
"permlevel": 1,
|
"permlevel": 1,
|
||||||
@ -559,7 +559,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 3,
|
"max_attachments": 3,
|
||||||
"modified": "2015-10-02 07:38:55.471712",
|
"modified": "2015-10-28 16:14:25.640730",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Leave Application",
|
"name": "Leave Application",
|
||||||
|
@ -100,7 +100,7 @@ class LeaveApplication(Document):
|
|||||||
|
|
||||||
if not is_lwp(self.leave_type):
|
if not is_lwp(self.leave_type):
|
||||||
self.leave_balance = get_leave_balance(self.employee,
|
self.leave_balance = get_leave_balance(self.employee,
|
||||||
self.leave_type, self.fiscal_year)["leave_balance"]
|
self.leave_type, self.from_date, self.to_date)["leave_balance"]
|
||||||
|
|
||||||
if self.status != "Rejected" \
|
if self.status != "Rejected" \
|
||||||
and self.leave_balance - self.total_leave_days < 0:
|
and self.leave_balance - self.total_leave_days < 0:
|
||||||
@ -122,9 +122,8 @@ class LeaveApplication(Document):
|
|||||||
employee = %(employee)s
|
employee = %(employee)s
|
||||||
and docstatus < 2
|
and docstatus < 2
|
||||||
and status in ("Open", "Approved")
|
and status in ("Open", "Approved")
|
||||||
and (from_date between %(from_date)s and %(to_date)s
|
and to_date >= %(from_date)s
|
||||||
or to_date between %(from_date)s and %(to_date)s
|
and from_date <= %(to_date)s
|
||||||
or %(from_date)s between from_date and to_date)
|
|
||||||
and name != %(name)s""", {
|
and name != %(name)s""", {
|
||||||
"employee": self.employee,
|
"employee": self.employee,
|
||||||
"from_date": self.from_date,
|
"from_date": self.from_date,
|
||||||
@ -251,18 +250,18 @@ def get_total_leave_days(leave_app):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_leave_balance(employee, leave_type, fiscal_year):
|
def get_leave_balance(employee, leave_type, from_date, to_date):
|
||||||
leave_all = frappe.db.sql("""select total_leaves_allocated
|
leave_all = frappe.db.sql("""select total_leaves_allocated
|
||||||
from `tabLeave Allocation` where employee = %s and leave_type = %s
|
from `tabLeave Allocation` where employee = %s and leave_type = %s
|
||||||
and fiscal_year = %s and docstatus = 1""", (employee,
|
and from_date<=%s and to_date>=%s and docstatus = 1""", (employee,
|
||||||
leave_type, fiscal_year))
|
leave_type, from_date, to_date))
|
||||||
|
|
||||||
leave_all = leave_all and flt(leave_all[0][0]) or 0
|
leave_all = leave_all and flt(leave_all[0][0]) or 0
|
||||||
|
|
||||||
leave_app = frappe.db.sql("""select SUM(total_leave_days)
|
leave_app = frappe.db.sql("""select SUM(total_leave_days)
|
||||||
from `tabLeave Application`
|
from `tabLeave Application`
|
||||||
where employee = %s and leave_type = %s and fiscal_year = %s
|
where employee = %s and leave_type = %s and to_date>=%s and from_date<=%s
|
||||||
and status="Approved" and docstatus = 1""", (employee, leave_type, fiscal_year))
|
and status="Approved" and docstatus = 1""", (employee, leave_type, from_date, to_date))
|
||||||
leave_app = leave_app and flt(leave_app[0][0]) or 0
|
leave_app = leave_app and flt(leave_app[0][0]) or 0
|
||||||
|
|
||||||
ret = {'leave_balance': leave_all - leave_app}
|
ret = {'leave_balance': leave_all - leave_app}
|
||||||
|
@ -145,16 +145,38 @@
|
|||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"fieldname": "fiscal_year",
|
"fieldname": "from_date",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Date",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"in_filter": 1,
|
"in_filter": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
"label": "Fiscal Year",
|
"label": "From Date",
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"options": "Fiscal Year",
|
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 1,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"fieldname": "to_date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "To Date",
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
"report_hide": 0,
|
"report_hide": 0,
|
||||||
@ -260,7 +282,7 @@
|
|||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-06-05 11:38:19.994852",
|
"modified": "2015-10-28 16:23:57.733900",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Leave Control Panel",
|
"name": "Leave Control Panel",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
from frappe.utils import cint, cstr, flt, nowdate, comma_and
|
from frappe.utils import cint, cstr, flt, nowdate, comma_and, date_diff
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
@ -27,9 +27,13 @@ class LeaveControlPanel(Document):
|
|||||||
return e
|
return e
|
||||||
|
|
||||||
def validate_values(self):
|
def validate_values(self):
|
||||||
for f in ["fiscal_year", "leave_type", "no_of_days"]:
|
for f in ["from_date", "to_date", "leave_type", "no_of_days"]:
|
||||||
if not self.get(f):
|
if not self.get(f):
|
||||||
frappe.throw(_("{0} is required").format(self.meta.get_label(f)))
|
frappe.throw(_("{0} is required").format(self.meta.get_label(f)))
|
||||||
|
|
||||||
|
def to_date_validation(self):
|
||||||
|
if date_diff(self.to_date, self.from_date) <= 0:
|
||||||
|
return "Invalid period"
|
||||||
|
|
||||||
def allocate_leave(self):
|
def allocate_leave(self):
|
||||||
self.validate_values()
|
self.validate_values()
|
||||||
@ -45,8 +49,8 @@ class LeaveControlPanel(Document):
|
|||||||
la.employee = cstr(d[0])
|
la.employee = cstr(d[0])
|
||||||
la.employee_name = frappe.db.get_value('Employee',cstr(d[0]),'employee_name')
|
la.employee_name = frappe.db.get_value('Employee',cstr(d[0]),'employee_name')
|
||||||
la.leave_type = self.leave_type
|
la.leave_type = self.leave_type
|
||||||
la.fiscal_year = self.fiscal_year
|
la.from_date = self.from_date
|
||||||
la.posting_date = nowdate()
|
la.to_date = self.to_date
|
||||||
la.carry_forward = cint(self.carry_forward)
|
la.carry_forward = cint(self.carry_forward)
|
||||||
la.new_leaves_allocated = flt(self.no_of_days)
|
la.new_leaves_allocated = flt(self.no_of_days)
|
||||||
la.docstatus = 1
|
la.docstatus = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user