def setUp(self): frappe.db.sql('''delete from `tabLeave Period`''') frappe.db.sql('''delete from `tabLeave Allocation`''') frappe.db.sql('''delete from `tabLeave Ledger Entry`''') frappe.db.sql('''delete from `tabAdditional Salary`''') # create the leave policy leave_policy = create_leave_policy( leave_type="_Test Leave Type Encashment", annual_allocation=10) leave_policy.submit() # create employee, salary structure and assignment self.employee = make_employee("*****@*****.**") frappe.db.set_value("Employee", self.employee, "leave_policy", leave_policy.name) salary_structure = make_salary_structure( "Salary Structure for Encashment", "Monthly", self.employee, other_details={"leave_encashment_amount_per_day": 50}) # create the leave period and assign the leaves self.leave_period = create_leave_period(add_months(today(), -3), add_months(today(), 3)) self.leave_period.grant_leave_allocation(employee=self.employee)
def setUp(self): frappe.db.sql("""delete from `tabLeave Period`""") frappe.db.sql("""delete from `tabLeave Policy Assignment`""") frappe.db.sql("""delete from `tabLeave Allocation`""") frappe.db.sql("""delete from `tabLeave Ledger Entry`""") frappe.db.sql("""delete from `tabAdditional Salary`""") # create the leave policy leave_policy = create_leave_policy( leave_type="_Test Leave Type Encashment", annual_allocation=10) leave_policy.submit() # create employee, salary structure and assignment self.employee = make_employee("*****@*****.**") self.leave_period = create_leave_period(add_months(today(), -3), add_months(today(), 3)) data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": self.leave_period.name, } leave_policy_assignments = create_assignment_for_multiple_employees( [self.employee], frappe._dict(data)) salary_structure = make_salary_structure( "Salary Structure for Encashment", "Monthly", self.employee, other_details={"leave_encashment_amount_per_day": 50}, )
def test_allow_to_grant_all_leave_after_cancellation_of_every_leave_allocation( self): leave_period = get_leave_period() employee = get_employee() # create the leave policy with leave type "_Test Leave Type", allocation = 10 leave_policy = create_leave_policy() leave_policy.submit() data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": leave_period.name } leave_policy_assignments = create_assignment_for_multiple_employees( [employee.name], frappe._dict(data)) leave_policy_assignment_doc = frappe.get_doc( "Leave Policy Assignment", leave_policy_assignments[0]) leave_policy_assignment_doc.grant_leave_alloc_for_employee() leave_policy_assignment_doc.reload() # every leave is allocated no more leave can be granted now self.assertEqual(leave_policy_assignment_doc.leaves_allocated, 1) leave_allocation = frappe.get_list("Leave Allocation", filters={ "employee": employee.name, "leave_policy": leave_policy.name, "leave_policy_assignment": leave_policy_assignments[0], "docstatus": 1 })[0] leave_alloc_doc = frappe.get_doc("Leave Allocation", leave_allocation) # User all allowed to grant leave when there is no allocation against assignment leave_alloc_doc.cancel() leave_alloc_doc.delete() leave_policy_assignment_doc.reload() # User are now allowed to grant leave self.assertEqual(leave_policy_assignment_doc.leaves_allocated, 0)
def test_grant_leaves(self): leave_period = get_leave_period() employee = get_employee() # create the leave policy with leave type "_Test Leave Type", allocation = 10 leave_policy = create_leave_policy() leave_policy.submit() data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": leave_period.name } leave_policy_assignments = create_assignment_for_multiple_employees( [employee.name], frappe._dict(data)) leave_policy_assignment_doc = frappe.get_doc( "Leave Policy Assignment", leave_policy_assignments[0]) leave_policy_assignment_doc.grant_leave_alloc_for_employee() leave_policy_assignment_doc.reload() self.assertEqual(leave_policy_assignment_doc.leaves_allocated, 1) leave_allocation = frappe.get_list("Leave Allocation", filters={ "employee": employee.name, "leave_policy": leave_policy.name, "leave_policy_assignment": leave_policy_assignments[0], "docstatus": 1 })[0] leave_alloc_doc = frappe.get_doc("Leave Allocation", leave_allocation) self.assertEqual(leave_alloc_doc.new_leaves_allocated, 10) self.assertEqual(leave_alloc_doc.leave_type, "_Test Leave Type") self.assertEqual(leave_alloc_doc.from_date, leave_period.from_date) self.assertEqual(leave_alloc_doc.to_date, leave_period.to_date) self.assertEqual(leave_alloc_doc.leave_policy, leave_policy.name) self.assertEqual(leave_alloc_doc.leave_policy_assignment, leave_policy_assignments[0])
def setUp(self): frappe.db.delete("Leave Period") frappe.db.delete("Leave Policy Assignment") frappe.db.delete("Leave Allocation") frappe.db.delete("Leave Ledger Entry") frappe.db.delete("Additional Salary") frappe.db.delete("Leave Encashment") if not frappe.db.exists("Leave Type", "_Test Leave Type Encashment"): frappe.get_doc(test_records[2]).insert() date = getdate() year_start = getdate(get_year_start(date)) year_end = getdate(get_year_ending(date)) make_holiday_list("_Test Leave Encashment", year_start, year_end) # create the leave policy leave_policy = create_leave_policy( leave_type="_Test Leave Type Encashment", annual_allocation=10 ) leave_policy.submit() # create employee, salary structure and assignment self.employee = make_employee("*****@*****.**", company="_Test Company") self.leave_period = create_leave_period(year_start, year_end, "_Test Company") data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": self.leave_period.name, } leave_policy_assignments = create_assignment_for_multiple_employees( [self.employee], frappe._dict(data) ) salary_structure = make_salary_structure( "Salary Structure for Encashment", "Monthly", self.employee, other_details={"leave_encashment_amount_per_day": 50}, )
def test_grant_leaves(self): leave_period = get_leave_period() # allocation = 10 leave_policy = create_leave_policy() leave_policy.submit() self.employee.date_of_joining = get_first_day(leave_period.from_date) self.employee.save() data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": leave_period.name, } leave_policy_assignments = create_assignment_for_multiple_employees( [self.employee.name], frappe._dict(data)) self.assertEqual( frappe.db.get_value("Leave Policy Assignment", leave_policy_assignments[0], "leaves_allocated"), 1, ) leave_allocation = frappe.get_list( "Leave Allocation", filters={ "employee": self.employee.name, "leave_policy": leave_policy.name, "leave_policy_assignment": leave_policy_assignments[0], "docstatus": 1, }, )[0] leave_alloc_doc = frappe.get_doc("Leave Allocation", leave_allocation) self.assertEqual(leave_alloc_doc.new_leaves_allocated, 10) self.assertEqual(leave_alloc_doc.leave_type, "_Test Leave Type") self.assertEqual(getdate(leave_alloc_doc.from_date), getdate(leave_period.from_date)) self.assertEqual(getdate(leave_alloc_doc.to_date), getdate(leave_period.to_date)) self.assertEqual(leave_alloc_doc.leave_policy, leave_policy.name) self.assertEqual(leave_alloc_doc.leave_policy_assignment, leave_policy_assignments[0])
def test_allow_to_grant_all_leave_after_cancellation_of_every_leave_allocation( self): leave_period = get_leave_period() # create the leave policy with leave type "_Test Leave Type", allocation = 10 leave_policy = create_leave_policy() leave_policy.submit() data = { "assignment_based_on": "Leave Period", "leave_policy": leave_policy.name, "leave_period": leave_period.name, } leave_policy_assignments = create_assignment_for_multiple_employees( [self.employee.name], frappe._dict(data)) # every leave is allocated no more leave can be granted now self.assertEqual( frappe.db.get_value("Leave Policy Assignment", leave_policy_assignments[0], "leaves_allocated"), 1, ) leave_allocation = frappe.get_list( "Leave Allocation", filters={ "employee": self.employee.name, "leave_policy": leave_policy.name, "leave_policy_assignment": leave_policy_assignments[0], "docstatus": 1, }, )[0] leave_alloc_doc = frappe.get_doc("Leave Allocation", leave_allocation) leave_alloc_doc.cancel() leave_alloc_doc.delete() self.assertEqual( frappe.db.get_value("Leave Policy Assignment", leave_policy_assignments[0], "leaves_allocated"), 0, )