def test_employee_leave_balance(self): frappe.get_doc(test_records[0]).insert() # 5 leaves allocation1 = make_allocation_record( employee=self.employee_id, from_date=add_days(self.year_start, -11), to_date=add_days(self.year_start, -1), leaves=5, ) # 30 leaves allocation2 = make_allocation_record(employee=self.employee_id, from_date=self.year_start, to_date=self.year_end) # expires 5 leaves process_expired_allocation() # 4 days leave first_sunday = get_first_sunday(self.holiday_list, for_date=self.year_start) leave_application = make_leave_application(self.employee_id, add_days(first_sunday, 1), add_days(first_sunday, 4), "_Test Leave Type") leave_application.reload() filters = frappe._dict({ "from_date": allocation1.from_date, "to_date": allocation2.to_date, "employee": self.employee_id, }) report = execute(filters) expected_data = [{ "leave_type": "_Test Leave Type", "employee": self.employee_id, "employee_name": "*****@*****.**", "leaves_allocated": flt(allocation1.new_leaves_allocated + allocation2.new_leaves_allocated), "leaves_expired": flt(allocation1.new_leaves_allocated), "opening_balance": flt(0), "leaves_taken": flt(leave_application.total_leave_days), "closing_balance": flt(allocation2.new_leaves_allocated - leave_application.total_leave_days), "indent": 1, }] self.assertEqual(report[1], expected_data)
def test_carry_forward_leaves_expiry(self): leave_type = create_leave_type( leave_type_name="_Test_CF_leave_expiry", is_carry_forward=1, expire_carry_forwarded_leaves_after_days=90, ) leave_type.save() # initial leave allocation leave_allocation = create_leave_allocation( employee=self.employee.name, employee_name=self.employee.employee_name, leave_type="_Test_CF_leave_expiry", from_date=add_months(nowdate(), -24), to_date=add_months(nowdate(), -12), carry_forward=0, ) leave_allocation.submit() leave_allocation = create_leave_allocation( employee=self.employee.name, employee_name=self.employee.employee_name, leave_type="_Test_CF_leave_expiry", from_date=add_days(nowdate(), -90), to_date=add_days(nowdate(), 100), carry_forward=1, ) leave_allocation.submit() # expires all the carry forwarded leaves after 90 days process_expired_allocation() # leave allocation with carry forward of only new leaves allocated leave_allocation_1 = create_leave_allocation( employee=self.employee.name, employee_name=self.employee.employee_name, leave_type="_Test_CF_leave_expiry", carry_forward=1, from_date=add_months(nowdate(), 6), to_date=add_months(nowdate(), 12), ) leave_allocation_1.submit() self.assertEqual(leave_allocation_1.unused_leaves, leave_allocation.new_leaves_allocated)
def test_carry_forward_leaves_expiry(self): frappe.db.sql("delete from `tabLeave Allocation`") frappe.db.sql("delete from `tabLeave Ledger Entry`") leave_type = create_leave_type( leave_type_name="_Test_CF_leave_expiry", is_carry_forward=1, expire_carry_forwarded_leaves_after_days=90) leave_type.save() # initial leave allocation leave_allocation = create_leave_allocation( leave_type="_Test_CF_leave_expiry", 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", from_date=add_days(nowdate(), -90), to_date=add_days(nowdate(), 100), carry_forward=1) leave_allocation.submit() # expires all the carry forwarded leaves after 90 days process_expired_allocation() # leave allocation with carry forward of only new leaves allocated leave_allocation_1 = create_leave_allocation( leave_type="_Test_CF_leave_expiry", carry_forward=1, from_date=add_months(nowdate(), 6), to_date=add_months(nowdate(), 12)) leave_allocation_1.submit() self.assertEquals(leave_allocation_1.unused_leaves, leave_allocation.new_leaves_allocated)
def test_employee_leave_balance_summary(self): frappe.get_doc(test_records[0]).insert() # 5 leaves allocation1 = make_allocation_record( employee=self.employee_id, from_date=add_days(self.year_start, -11), to_date=add_days(self.year_start, -1), leaves=5, ) # 30 leaves allocation2 = make_allocation_record( employee=self.employee_id, from_date=self.year_start, to_date=self.year_end ) # 2 days leave within the first allocation leave_application1 = make_leave_application( self.employee_id, add_days(self.year_start, -11), add_days(self.year_start, -10), "_Test Leave Type", ) leave_application1.reload() # expires 3 leaves process_expired_allocation() # 4 days leave within the second allocation first_sunday = get_first_sunday(self.holiday_list, for_date=self.year_start) leave_application2 = make_leave_application( self.employee_id, add_days(first_sunday, 1), add_days(first_sunday, 4), "_Test Leave Type" ) leave_application2.reload() filters = frappe._dict( { "date": add_days(leave_application2.to_date, 1), "company": "_Test Company", "employee": self.employee_id, } ) report = execute(filters) expected_data = [ [ self.employee_id, "*****@*****.**", frappe.db.get_value("Employee", self.employee_id, "department"), flt( allocation1.new_leaves_allocated # allocated = 5 + allocation2.new_leaves_allocated # allocated = 30 - leave_application1.total_leave_days # leaves taken in the 1st alloc = 2 - ( allocation1.new_leaves_allocated - leave_application1.total_leave_days ) # leaves expired from 1st alloc = 3 - leave_application2.total_leave_days # leaves taken in the 2nd alloc = 4 ), ] ] self.assertEqual(report[1], expected_data)