|
|
@ -12,15 +12,11 @@ from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type |
|
|
|
class TestLeaveAllocation(unittest.TestCase): |
|
|
|
@classmethod |
|
|
|
def setUpClass(cls): |
|
|
|
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list |
|
|
|
|
|
|
|
frappe.db.sql("delete from `tabLeave Period`") |
|
|
|
|
|
|
|
emp_id = make_employee("test_emp_leave_allocation@salary.com") |
|
|
|
cls.employee = frappe.get_doc("Employee", emp_id) |
|
|
|
|
|
|
|
make_holiday_list() |
|
|
|
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List") |
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
frappe.db.rollback() |
|
|
|
|
|
|
@ -90,6 +86,8 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
|
|
|
|
# initial leave allocation = 15 |
|
|
|
leave_allocation = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name, |
|
|
|
leave_type="_Test_CF_leave", |
|
|
|
from_date=add_months(nowdate(), -12), |
|
|
|
to_date=add_months(nowdate(), -1), |
|
|
@ -99,6 +97,8 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
# carry forwarded leaves considering maximum_carry_forwarded_leaves |
|
|
|
# new_leaves = 15, carry_forwarded = 10 |
|
|
|
leave_allocation_1 = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name, |
|
|
|
leave_type="_Test_CF_leave", |
|
|
|
carry_forward=1) |
|
|
|
leave_allocation_1.submit() |
|
|
@ -110,6 +110,8 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
# carry forwarded leaves considering max_leave_allowed |
|
|
|
# max_leave_allowed = 30, new_leaves = 25, carry_forwarded = 5 |
|
|
|
leave_allocation_2 = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name, |
|
|
|
leave_type="_Test_CF_leave", |
|
|
|
carry_forward=1, |
|
|
|
new_leaves_allocated=25) |
|
|
@ -126,6 +128,8 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
|
|
|
|
# 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), |
|
|
@ -133,6 +137,8 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
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), |
|
|
@ -144,6 +150,8 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
|
|
|
|
# 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), |
|
|
@ -153,7 +161,10 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
self.assertEqual(leave_allocation_1.unused_leaves, leave_allocation.new_leaves_allocated) |
|
|
|
|
|
|
|
def test_creation_of_leave_ledger_entry_on_submit(self): |
|
|
|
leave_allocation = create_leave_allocation() |
|
|
|
leave_allocation = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name |
|
|
|
) |
|
|
|
leave_allocation.submit() |
|
|
|
|
|
|
|
leave_ledger_entry = frappe.get_all('Leave Ledger Entry', fields='*', filters=dict(transaction_name=leave_allocation.name)) |
|
|
@ -168,7 +179,10 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
self.assertFalse(frappe.db.exists("Leave Ledger Entry", {'transaction_name':leave_allocation.name})) |
|
|
|
|
|
|
|
def test_leave_addition_after_submit(self): |
|
|
|
leave_allocation = create_leave_allocation() |
|
|
|
leave_allocation = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name |
|
|
|
) |
|
|
|
leave_allocation.submit() |
|
|
|
self.assertTrue(leave_allocation.total_leaves_allocated, 15) |
|
|
|
leave_allocation.new_leaves_allocated = 40 |
|
|
@ -176,7 +190,10 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
self.assertTrue(leave_allocation.total_leaves_allocated, 40) |
|
|
|
|
|
|
|
def test_leave_subtraction_after_submit(self): |
|
|
|
leave_allocation = create_leave_allocation() |
|
|
|
leave_allocation = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name |
|
|
|
) |
|
|
|
leave_allocation.submit() |
|
|
|
self.assertTrue(leave_allocation.total_leaves_allocated, 15) |
|
|
|
leave_allocation.new_leaves_allocated = 10 |
|
|
@ -184,7 +201,15 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
self.assertTrue(leave_allocation.total_leaves_allocated, 10) |
|
|
|
|
|
|
|
def test_validation_against_leave_application_after_submit(self): |
|
|
|
leave_allocation = create_leave_allocation() |
|
|
|
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list |
|
|
|
|
|
|
|
make_holiday_list() |
|
|
|
frappe.db.set_value("Company", self.employee.company, "default_holiday_list", "Salary Slip Test Holiday List") |
|
|
|
|
|
|
|
leave_allocation = create_leave_allocation( |
|
|
|
employee=self.employee.name, |
|
|
|
employee_name=self.employee.employee_name |
|
|
|
) |
|
|
|
leave_allocation.submit() |
|
|
|
self.assertTrue(leave_allocation.total_leaves_allocated, 15) |
|
|
|
|
|
|
@ -194,7 +219,7 @@ class TestLeaveAllocation(unittest.TestCase): |
|
|
|
"leave_type": "_Test Leave Type", |
|
|
|
"from_date": add_months(nowdate(), 2), |
|
|
|
"to_date": add_months(add_days(nowdate(), 10), 2), |
|
|
|
"company": erpnext.get_default_company() or "_Test Company", |
|
|
|
"company": self.employee.company, |
|
|
|
"docstatus": 1, |
|
|
|
"status": "Approved", |
|
|
|
"leave_approver": 'test@example.com' |
|
|
|