feat: create ledger entry for each earned leave
This commit is contained in:
parent
050f65beb4
commit
3863fc5fb2
@ -270,7 +270,7 @@ def allocate_earned_leaves():
|
||||
filters={'is_earned_leave' : 1})
|
||||
today = getdate()
|
||||
divide_by_frequency = {"Yearly": 1, "Half-Yearly": 6, "Quarterly": 4, "Monthly": 12}
|
||||
if e_leave_types:
|
||||
|
||||
for e_leave_type in e_leave_types:
|
||||
leave_allocations = frappe.db.sql("""select name, employee, from_date, to_date from `tabLeave Allocation` where '{0}'
|
||||
between from_date and to_date and docstatus=1 and leave_type='{1}'"""
|
||||
@ -291,10 +291,22 @@ def allocate_earned_leaves():
|
||||
else:
|
||||
earned_leaves = round(earned_leaves)
|
||||
|
||||
allocated_leaves = frappe.db.get_value('Leave Allocation', allocation.name, 'total_leaves_allocated')
|
||||
new_allocation = flt(allocated_leaves) + flt(earned_leaves)
|
||||
allocation = frappe.get_doc('Leave Allocation', allocation.name)
|
||||
new_allocation = flt(allocation.total_leaves_allocated) + flt(earned_leaves)
|
||||
new_allocation = new_allocation if new_allocation <= e_leave_type.max_leaves_allowed else e_leave_type.max_leaves_allowed
|
||||
frappe.db.set_value('Leave Allocation', allocation.name, 'total_leaves_allocated', new_allocation)
|
||||
|
||||
if new_allocation == allocation.total_leaves_allocated:
|
||||
continue
|
||||
allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
|
||||
create_earned_leave_ledger_entry(allocation, earned_leaves, today)
|
||||
|
||||
|
||||
def create_earned_leave_ledger_entry(allocation, earned_leaves, date):
|
||||
''' Create leave ledger entry based on the earned leave frequency '''
|
||||
allocation.new_leaves_allocated = earned_leaves
|
||||
allocation.from_date = date
|
||||
allocation.carry_forwarded_leaves = 0
|
||||
allocation.create_leave_ledger_entry()
|
||||
|
||||
def check_frequency_hit(from_date, to_date, frequency):
|
||||
'''Return True if current date matches frequency'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user