We have 30 leaves in a year . I want to assign 15 leave from jan to june and other 15 leave from july to dec. In one leave type, how can i create this leave type. Can anyone suggest me.
hi,
I am not sure if this will sort your issue but you can use earned leave which will grant the employee 2.5 days each month
yes this is ok and I had already done this . but I want 6 month earned leave on 1st of Jan and next 6th month earned leave automatically credit to 1st of July in employee account.
Do the changes on leave_policy_assignment.py file and get the result
def get_leaves_for_passed_months(self, leave_type, new_leaves_allocated, leave_type_details, date_of_joining):
from erpnext.hr.utils import get_monthly_earned_leave
current_date = frappe.flags.current_date or getdate()
if current_date > getdate(self.effective_to):
current_date = getdate(self.effective_to)
from_date = getdate(self.effective_from)
if getdate(date_of_joining) > from_date:
from_date = getdate(date_of_joining)
months_passed = 0
based_on_doj = leave_type_details.get(leave_type).based_on_date_of_joining
if current_date.year == from_date.year and current_date.month >= from_date.month:
months_passed = current_date.month - from_date.month
months_passed = add_current_month_if_applicable(months_passed, date_of_joining, based_on_doj)
elif current_date.year > from_date.year:
months_passed = (12 - from_date.month) + current_date.month
months_passed = add_current_month_if_applicable(months_passed, date_of_joining, based_on_doj)
# created here half yarly leave concept
# suppose we get 15-15 days leave every half year
# we will devide here total yearly leave with 12 and multiply with remaining month and allot all remaining month leave in one time
# custom code
#custom_leave_type = leave_type_details.get(leave_type).leave_type
#frappe.throw(leave_type_details.get(leave_type).earned_leave_frequency)
if leave_type_details.get(leave_type).earned_leave_frequency=='Half-Yearly':
leave_per_month = new_leaves_allocated/12
if date_of_joining.year<current_date.year:
new_leaves_allocated = round(leave_per_month*6)
else:
if current_date.month<=6:
months_passed = (6-date_of_joining.month)+1
new_leaves_allocated = round(leave_per_month*months_passed)
elif current_date.month>6:
months_passed = (12-current_date.month)+1
new_leaves_allocated = round(leave_per_month*months_passed)
else:
#core code
if months_passed > 0:
monthly_earned_leave = get_monthly_earned_leave(new_leaves_allocated,
leave_type_details.get(leave_type).earned_leave_frequency, leave_type_details.get(leave_type).rounding)
new_leaves_allocated = monthly_earned_leave * months_passed
else:
new_leaves_allocated = 0
#core code
# custom code
return new_leaves_allocated