def test_creation_of_leave_ledger_entry_on_submit(self): employee = get_employee() leave_type = create_leave_type(leave_type_name = 'Test Leave Type 1') leave_type.save() leave_allocation = create_leave_allocation(employee=employee.name, employee_name=employee.employee_name, leave_type=leave_type.name) leave_allocation.submit() leave_application = frappe.get_doc(dict( doctype = 'Leave Application', employee = employee.name, leave_type = leave_type.name, from_date = add_days(nowdate(), 1), to_date = add_days(nowdate(), 4), description = "_Test Reason", company = "_Test Company", docstatus = 1, status = "Approved" )) leave_application.submit() leave_ledger_entry = frappe.get_all('Leave Ledger Entry', fields='*', filters=dict(transaction_name=leave_application.name)) self.assertEquals(leave_ledger_entry[0].employee, leave_application.employee) self.assertEquals(leave_ledger_entry[0].leave_type, leave_application.leave_type) self.assertEquals(leave_ledger_entry[0].leaves, leave_application.total_leave_days * -1) # check if leave ledger entry is deleted on cancellation leave_application.cancel() self.assertFalse(frappe.db.exists("Leave Ledger Entry", {'transaction_name':leave_application.name}))
def create_carry_forwarded_allocation(employee, leave_type): # initial leave allocation leave_allocation = create_leave_allocation( leave_type="_Test_CF_leave_expiry", employee=employee.name, employee_name=employee.employee_name, from_date=add_months(nowdate(), -24), to_date=add_months(nowdate(), -12), carry_forward=0) leave_allocation.submit() leave_allocation = create_leave_allocation( leave_type="_Test_CF_leave_expiry", employee=employee.name, employee_name=employee.employee_name, from_date=add_days(nowdate(), -84), to_date=add_days(nowdate(), 100), carry_forward=1) leave_allocation.submit()
def test_payment_days_based_on_leave_application(self): no_of_days = self.get_no_of_days() # Payroll based on attendance frappe.db.set_value("Payroll Settings", None, "payroll_based_on", "Leave") emp_id = make_employee( "*****@*****.**") frappe.db.set_value("Employee", emp_id, { "relieving_date": None, "status": "Active"}) frappe.db.set_value( "Leave Type", "Leave Without Pay", "include_holiday", 0) month_start_date = get_first_day(nowdate()) month_end_date = get_last_day(nowdate()) first_sunday = frappe.db.sql(""" select holiday_date from `tabHoliday` where parent = 'Salary Slip Test Holiday List' and holiday_date between %s and %s order by holiday_date """, (month_start_date, month_end_date))[0][0] make_leave_application(emp_id, first_sunday, add_days( first_sunday, 3), "Leave Without Pay") leave_type_ppl = create_leave_type( leave_type_name="Test Partially Paid Leave", is_ppl=1) leave_type_ppl.save() alloc = create_leave_allocation( employee=emp_id, from_date=add_days(first_sunday, 4), to_date=add_days(first_sunday, 10), new_leaves_allocated=3, leave_type="Test Partially Paid Leave") alloc.save() alloc.submit() # two day leave ppl with fraction_of_daily_salary_per_leave = 0.5 equivalent to single day lwp make_leave_application(emp_id, add_days(first_sunday, 4), add_days( first_sunday, 5), "Test Partially Paid Leave") ss = make_employee_salary_slip( "*****@*****.**", "Monthly", "Test Payment Based On Leave Application") self.assertEqual(ss.leave_without_pay, 4) days_in_month = no_of_days[0] no_of_holidays = no_of_days[1] self.assertEqual(ss.payment_days, days_in_month - no_of_holidays - 4) frappe.db.set_value("Payroll Settings", None, "payroll_based_on", "Leave")
def test_earned_leave_alloc_for_passed_months_with_cf_leaves_based_on_leave_period( self): from erpnext.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation leave_period, leave_policy = setup_leave_period_and_policy( get_first_day(add_months(getdate(), -2))) # initial leave allocation = 5 leave_allocation = create_leave_allocation( employee=self.employee.name, employee_name=self.employee.employee_name, leave_type="Test Earned Leave", from_date=add_months(getdate(), -12), to_date=add_months(getdate(), -3), new_leaves_allocated=5, carry_forward=0, ) leave_allocation.submit() # Case 3: assignment created on the last day of the leave period's latter month with carry forwarding frappe.flags.current_date = get_last_day(add_months(getdate(), -1)) data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": leave_period.name, "carry_forward": 1, } # carry forwarded leaves = 5, 3 leaves allocated for passed months leave_policy_assignments = create_assignment_for_multiple_employees( [self.employee.name], frappe._dict(data)) details = frappe.db.get_value( "Leave Allocation", {"leave_policy_assignment": leave_policy_assignments[0]}, [ "total_leaves_allocated", "new_leaves_allocated", "unused_leaves", "name" ], as_dict=True, ) self.assertEqual(details.new_leaves_allocated, 2) self.assertEqual(details.unused_leaves, 5) self.assertEqual(details.total_leaves_allocated, 7)