fix: minor changes
This commit is contained in:
parent
439313e524
commit
bd999b0908
@ -94,19 +94,10 @@ frappe.ui.form.on("Leave Allocation", {
|
|||||||
calculate_total_leaves_allocated: function(frm) {
|
calculate_total_leaves_allocated: function(frm) {
|
||||||
if (cint(frm.doc.carry_forward) == 1 && frm.doc.leave_type && frm.doc.employee) {
|
if (cint(frm.doc.carry_forward) == 1 && frm.doc.leave_type && frm.doc.employee) {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.hr.doctype.leave_allocation.leave_allocation.get_carry_forwarded_leaves",
|
method: "set_total_leaves_allocated",
|
||||||
args: {
|
doc: frm.doc,
|
||||||
"employee": frm.doc.employee,
|
|
||||||
"date": frm.doc.from_date,
|
|
||||||
"leave_type": frm.doc.leave_type,
|
|
||||||
"carry_forward": frm.doc.carry_forward
|
|
||||||
},
|
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (!r.exc && r.message) {
|
frm.refresh_fields();
|
||||||
frm.set_value('carry_forwarded_leaves', r.message);
|
|
||||||
frm.set_value("total_leaves_allocated",
|
|
||||||
flt(r.message) + flt(frm.doc.new_leaves_allocated));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (cint(frm.doc.carry_forward) == 0) {
|
} else if (cint(frm.doc.carry_forward) == 0) {
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class LeaveAllocation(Document):
|
|||||||
args = dict(
|
args = dict(
|
||||||
leaves=self.carry_forwarded_leaves,
|
leaves=self.carry_forwarded_leaves,
|
||||||
from_date=self.from_date,
|
from_date=self.from_date,
|
||||||
to_date=add_days(self.from_date, expiry_days) if expiry_days else self.to_date,
|
to_date=add_days(self.from_date, expiry_days - 1) if expiry_days else self.to_date,
|
||||||
is_carry_forward=1
|
is_carry_forward=1
|
||||||
)
|
)
|
||||||
create_leave_ledger_entry(self, args, submit)
|
create_leave_ledger_entry(self, args, submit)
|
||||||
@ -132,11 +132,13 @@ class LeaveAllocation(Document):
|
|||||||
''' expires allocation '''
|
''' expires allocation '''
|
||||||
date = self.to_date if current else self.from_date
|
date = self.to_date if current else self.from_date
|
||||||
leaves = get_unused_leaves(self.employee, self.leave_type, date)
|
leaves = get_unused_leaves(self.employee, self.leave_type, date)
|
||||||
|
ref_name = self.name if current else self.get_previous_allocation()
|
||||||
|
|
||||||
if leaves:
|
if leaves:
|
||||||
expiry_date = today() if current else add_days(self.from_date, -1)
|
expiry_date = today() if current else add_days(self.from_date, -1)
|
||||||
args = dict(
|
args = dict(
|
||||||
leaves=flt(leaves) * -1,
|
leaves=flt(leaves) * -1,
|
||||||
|
transaction_name=ref_name,
|
||||||
from_date=expiry_date,
|
from_date=expiry_date,
|
||||||
to_date=expiry_date,
|
to_date=expiry_date,
|
||||||
is_carry_forward=0,
|
is_carry_forward=0,
|
||||||
@ -147,6 +149,17 @@ class LeaveAllocation(Document):
|
|||||||
if current:
|
if current:
|
||||||
frappe.db.set_value("Leave Allocation", self.name, "status", "Expired")
|
frappe.db.set_value("Leave Allocation", self.name, "status", "Expired")
|
||||||
|
|
||||||
|
def get_previous_allocation(self):
|
||||||
|
return frappe.db.get_value("Leave Allocation",
|
||||||
|
filters={
|
||||||
|
'to_date': ("<", self.from_date),
|
||||||
|
'leave_type': self.leave_type,
|
||||||
|
'employee': self.employee,
|
||||||
|
'docstatus': 1
|
||||||
|
},
|
||||||
|
order_by='to_date DESC',
|
||||||
|
fieldname=['name'])
|
||||||
|
|
||||||
def get_leave_allocation_for_period(employee, leave_type, from_date, to_date):
|
def get_leave_allocation_for_period(employee, leave_type, from_date, to_date):
|
||||||
leave_allocated = 0
|
leave_allocated = 0
|
||||||
leave_allocations = frappe.db.sql("""
|
leave_allocations = frappe.db.sql("""
|
||||||
|
|||||||
@ -49,7 +49,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
async: false,
|
async: false,
|
||||||
args: {
|
args: {
|
||||||
employee: frm.doc.employee,
|
employee: frm.doc.employee,
|
||||||
date: frm.doc.posting_date
|
date: frm.doc.from_date? frm.doc.from_date:frm.doc.posting_date
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (!r.exc && r.message['leave_allocation']) {
|
if (!r.exc && r.message['leave_allocation']) {
|
||||||
@ -124,6 +124,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
from_date: function(frm) {
|
from_date: function(frm) {
|
||||||
|
frm.trigger("make_dashboard");
|
||||||
frm.trigger("half_day_datepicker");
|
frm.trigger("half_day_datepicker");
|
||||||
frm.trigger("calculate_total_days");
|
frm.trigger("calculate_total_days");
|
||||||
},
|
},
|
||||||
|
|||||||
@ -417,9 +417,9 @@ def get_leave_details(employee, date):
|
|||||||
allocation = allocation_records.get(d, frappe._dict())
|
allocation = allocation_records.get(d, frappe._dict())
|
||||||
remaining_leaves = get_leave_balance_on(employee, d, date, to_date = allocation.to_date,
|
remaining_leaves = get_leave_balance_on(employee, d, date, to_date = allocation.to_date,
|
||||||
consider_all_leaves_in_the_allocation_period=True)
|
consider_all_leaves_in_the_allocation_period=True)
|
||||||
date = allocation.to_date
|
end_date = allocation.to_date
|
||||||
leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, date) * -1
|
leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, end_date) * -1
|
||||||
leaves_pending = get_pending_leaves_for_period(employee, d, allocation.from_date, date)
|
leaves_pending = get_pending_leaves_for_period(employee, d, allocation.from_date, end_date)
|
||||||
|
|
||||||
leave_allocation[d] = {
|
leave_allocation[d] = {
|
||||||
"total_leaves": allocation.total_leaves_allocated,
|
"total_leaves": allocation.total_leaves_allocated,
|
||||||
@ -435,14 +435,17 @@ def get_leave_details(employee, date):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_leave_balance_on(employee, leave_type, date, to_date=nowdate(), allocation_records=None,
|
def get_leave_balance_on(employee, leave_type, date, to_date=nowdate(), consider_all_leaves_in_the_allocation_period=False):
|
||||||
consider_all_leaves_in_the_allocation_period=False):
|
'''
|
||||||
''' Returns leave balance till date and fetches expiry date based on to_date
|
Returns leave balance on date
|
||||||
to calculate minimum remaining leave balance '''
|
:param employee: employee name
|
||||||
|
:param leave_type: leave type
|
||||||
|
:param date: date to check balance on
|
||||||
|
:param to_date: future date to check for allocation expiry
|
||||||
|
:param consider_all_leaves_in_the_allocation_period: consider all leaves taken till the allocation end date
|
||||||
|
'''
|
||||||
|
|
||||||
if not allocation_records:
|
|
||||||
allocation_records = get_leave_allocation_records(employee, date, leave_type)
|
allocation_records = get_leave_allocation_records(employee, date, leave_type)
|
||||||
|
|
||||||
allocation = allocation_records.get(leave_type, frappe._dict())
|
allocation = allocation_records.get(leave_type, frappe._dict())
|
||||||
|
|
||||||
end_date = allocation.to_date if consider_all_leaves_in_the_allocation_period else date
|
end_date = allocation.to_date if consider_all_leaves_in_the_allocation_period else date
|
||||||
|
|||||||
@ -557,7 +557,7 @@ def create_carry_forwarded_allocation(employee, leave_type):
|
|||||||
leave_type="_Test_CF_leave_expiry",
|
leave_type="_Test_CF_leave_expiry",
|
||||||
employee=employee.name,
|
employee=employee.name,
|
||||||
employee_name=employee.employee_name,
|
employee_name=employee.employee_name,
|
||||||
from_date=add_days(nowdate(), -85),
|
from_date=add_days(nowdate(), -84),
|
||||||
to_date=add_days(nowdate(), 100),
|
to_date=add_days(nowdate(), 100),
|
||||||
carry_forward=1)
|
carry_forward=1)
|
||||||
leave_allocation.submit()
|
leave_allocation.submit()
|
||||||
|
|||||||
@ -101,7 +101,7 @@
|
|||||||
],
|
],
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"modified": "2019-06-06 20:33:37.531161",
|
"modified": "2019-06-21 00:37:07.782810",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Leave Ledger Entry",
|
"name": "Leave Ledger Entry",
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import add_days, today, flt
|
from frappe.utils import add_days, today, flt, DATE_FORMAT
|
||||||
|
|
||||||
class LeaveLedgerEntry(Document):
|
class LeaveLedgerEntry(Document):
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
@ -49,14 +49,31 @@ def create_leave_ledger_entry(ref_doc, args, submit=True):
|
|||||||
|
|
||||||
def delete_ledger_entry(ledger):
|
def delete_ledger_entry(ledger):
|
||||||
''' Delete ledger entry on cancel of leave application/allocation/encashment '''
|
''' Delete ledger entry on cancel of leave application/allocation/encashment '''
|
||||||
|
|
||||||
if ledger.transaction_type == "Leave Allocation":
|
if ledger.transaction_type == "Leave Allocation":
|
||||||
validate_leave_allocation_against_leave_application(ledger)
|
validate_leave_allocation_against_leave_application(ledger)
|
||||||
|
|
||||||
|
expired_entry = get_previous_expiry_ledger_entry(ledger)
|
||||||
frappe.db.sql("""DELETE
|
frappe.db.sql("""DELETE
|
||||||
FROM `tabLeave Ledger Entry`
|
FROM `tabLeave Ledger Entry`
|
||||||
WHERE
|
WHERE
|
||||||
`transaction_name`=%s""", (ledger.transaction_name))
|
`transaction_name`=%s
|
||||||
|
OR `name`=%s""", (ledger.transaction_name, expired_entry))
|
||||||
|
|
||||||
|
def get_previous_expiry_ledger_entry(ledger):
|
||||||
|
''' Returns the expiry ledger entry having same creation date as the ledger entry to be cancelled '''
|
||||||
|
creation_date = frappe.db.get_value("Leave Ledger Entry", filters={
|
||||||
|
'transaction_name': ledger.transaction_name,
|
||||||
|
'is_expired': 0
|
||||||
|
}, fieldname=['creation']).strftime(DATE_FORMAT)
|
||||||
|
|
||||||
|
return frappe.db.get_value("Leave Ledger Entry", filters={
|
||||||
|
'creation': ('like', creation_date+"%"),
|
||||||
|
'employee': ledger.employee,
|
||||||
|
'leave_type': ledger.leave_type,
|
||||||
|
'is_expired': 1,
|
||||||
|
'docstatus': 1,
|
||||||
|
'is_carry_forward': 0
|
||||||
|
}, fieldname=['name'])
|
||||||
|
|
||||||
def process_expired_allocation():
|
def process_expired_allocation():
|
||||||
''' Check if a carry forwarded allocation has expired and create a expiry ledger entry '''
|
''' Check if a carry forwarded allocation has expired and create a expiry ledger entry '''
|
||||||
@ -70,7 +87,7 @@ def process_expired_allocation():
|
|||||||
leave_type = [record[0] for record in leave_type_records]
|
leave_type = [record[0] for record in leave_type_records]
|
||||||
expired_allocation = frappe.get_all("Leave Ledger Entry",
|
expired_allocation = frappe.get_all("Leave Ledger Entry",
|
||||||
filters={
|
filters={
|
||||||
'to_date': today(),
|
'to_date': add_days(today(), -1),
|
||||||
'transaction_type': 'Leave Allocation',
|
'transaction_type': 'Leave Allocation',
|
||||||
'is_carry_forward': 1,
|
'is_carry_forward': 1,
|
||||||
'leave_type': ('in', leave_type)
|
'leave_type': ('in', leave_type)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user