mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
[fixes] test leave allocation record creation
This commit is contained in:
@@ -44,7 +44,11 @@ _test_records = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class TestLeaveApplication(unittest.TestCase):
|
class TestLeaveApplication(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
|
||||||
|
frappe.db.sql("delete from `tab%s`" % dt)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
|
|
||||||
@@ -97,6 +101,8 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
|
|
||||||
frappe.db.set_value("Department", "_Test Department",
|
frappe.db.set_value("Department", "_Test Department",
|
||||||
"leave_block_list", "_Test Leave Block List")
|
"leave_block_list", "_Test Leave Block List")
|
||||||
|
|
||||||
|
make_allocation_record()
|
||||||
|
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
application.insert()
|
application.insert()
|
||||||
@@ -120,6 +126,9 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
add_role("test2@example.com", "Leave Approver")
|
add_role("test2@example.com", "Leave Approver")
|
||||||
|
|
||||||
frappe.set_user("test@example.com")
|
frappe.set_user("test@example.com")
|
||||||
|
|
||||||
|
make_allocation_record()
|
||||||
|
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
application.leave_approver = "test2@example.com"
|
application.leave_approver = "test2@example.com"
|
||||||
application.insert()
|
application.insert()
|
||||||
@@ -135,7 +144,9 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
add_role("test1@example.com", "Employee")
|
add_role("test1@example.com", "Employee")
|
||||||
add_role("test@example.com", "Leave Approver")
|
add_role("test@example.com", "Leave Approver")
|
||||||
self._add_employee_leave_approver("_T-Employee-0002", "test@example.com")
|
self._add_employee_leave_approver("_T-Employee-0002", "test@example.com")
|
||||||
|
|
||||||
|
make_allocation_record(employee="_T-Employee-0002")
|
||||||
|
|
||||||
application = self.get_application(_test_records[1])
|
application = self.get_application(_test_records[1])
|
||||||
application.leave_approver = "test@example.com"
|
application.leave_approver = "test@example.com"
|
||||||
|
|
||||||
@@ -175,6 +186,9 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
|
|
||||||
# create leave application as Employee
|
# create leave application as Employee
|
||||||
frappe.set_user("test@example.com")
|
frappe.set_user("test@example.com")
|
||||||
|
|
||||||
|
make_allocation_record()
|
||||||
|
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
application.leave_approver = "test1@example.com"
|
application.leave_approver = "test1@example.com"
|
||||||
application.insert()
|
application.insert()
|
||||||
@@ -196,6 +210,8 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com")
|
self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com")
|
||||||
self._remove_employee_leave_approver("_T-Employee-0001", "test1@example.com")
|
self._remove_employee_leave_approver("_T-Employee-0001", "test1@example.com")
|
||||||
|
|
||||||
|
make_allocation_record()
|
||||||
|
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
frappe.set_user("test@example.com")
|
frappe.set_user("test@example.com")
|
||||||
|
|
||||||
@@ -212,6 +228,9 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
# create leave application as employee
|
# create leave application as employee
|
||||||
# but submit as invalid leave approver - should raise exception
|
# but submit as invalid leave approver - should raise exception
|
||||||
frappe.set_user("test@example.com")
|
frappe.set_user("test@example.com")
|
||||||
|
|
||||||
|
make_allocation_record()
|
||||||
|
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
application.leave_approver = "test2@example.com"
|
application.leave_approver = "test2@example.com"
|
||||||
application.insert()
|
application.insert()
|
||||||
@@ -232,6 +251,9 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
frappe.db.set_value("Employee", "_T-Employee-0001", "department", None)
|
frappe.db.set_value("Employee", "_T-Employee-0001", "department", None)
|
||||||
|
|
||||||
frappe.set_user("test@example.com")
|
frappe.set_user("test@example.com")
|
||||||
|
|
||||||
|
make_allocation_record()
|
||||||
|
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
application.leave_approver = "test2@example.com"
|
application.leave_approver = "test2@example.com"
|
||||||
application.insert()
|
application.insert()
|
||||||
@@ -246,4 +268,19 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
|
frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
|
||||||
"_T-Employee-0001")
|
"_T-Employee-0001")
|
||||||
|
|
||||||
frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department)
|
frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department)
|
||||||
|
|
||||||
|
def make_allocation_record(employee=None, leave_type=None):
|
||||||
|
frappe.db.sql("delete from `tabLeave Allocation`")
|
||||||
|
|
||||||
|
allocation = frappe.get_doc({
|
||||||
|
"doctype": "Leave Allocation",
|
||||||
|
"employee": employee or "_T-Employee-0001",
|
||||||
|
"leave_type": leave_type or "_Test Leave Type",
|
||||||
|
"from_date": "2013-01-01",
|
||||||
|
"to_date": "2015-12-31",
|
||||||
|
"new_leaves_allocated": 30
|
||||||
|
})
|
||||||
|
|
||||||
|
allocation.insert(ignore_permissions=True)
|
||||||
|
allocation.submit()
|
||||||
|
|||||||
@@ -7,23 +7,14 @@ import frappe
|
|||||||
from frappe.utils import today
|
from frappe.utils import today
|
||||||
from erpnext.hr.doctype.employee.employee import make_salary_structure
|
from erpnext.hr.doctype.employee.employee import make_salary_structure
|
||||||
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
|
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
|
||||||
|
from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record
|
||||||
|
|
||||||
class TestSalarySlip(unittest.TestCase):
|
class TestSalarySlip(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
|
for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
|
||||||
frappe.db.sql("delete from `tab%s`" % dt)
|
frappe.db.sql("delete from `tab%s`" % dt)
|
||||||
|
|
||||||
allocation = frappe.get_doc({
|
make_allocation_record(leave_type="_Test Leave Type LWP")
|
||||||
"doctype": "Leave Allocation",
|
|
||||||
"employee": "_T-Employee-0001",
|
|
||||||
"leave_type": "_Test Leave Type LWP",
|
|
||||||
"from_date": "2013-01-01",
|
|
||||||
"to_date": "2015-12-31",
|
|
||||||
"new_leaves_allocated": 5
|
|
||||||
})
|
|
||||||
|
|
||||||
allocation.insert()
|
|
||||||
allocation.submit()
|
|
||||||
|
|
||||||
frappe.db.set_value("Holiday List", "_Test Holiday List", "is_default", 1)
|
frappe.db.set_value("Holiday List", "_Test Holiday List", "is_default", 1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user