test: pass leave type as params
This commit is contained in:
parent
70cf4a6796
commit
d01863707c
@ -1,7 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import unittest
|
||||
from frappe.utils import nowdate, add_months, getdate
|
||||
from frappe.utils import nowdate, add_months, getdate, add_days
|
||||
from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type
|
||||
|
||||
class TestLeaveAllocation(unittest.TestCase):
|
||||
@ -71,36 +71,27 @@ class TestLeaveAllocation(unittest.TestCase):
|
||||
def test_carry_forward_allocation(self):
|
||||
frappe.db.sql("delete from `tabLeave Allocation`")
|
||||
|
||||
employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0])
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Leave Allocation",
|
||||
"__islocal": 1,
|
||||
"employee": employee.name,
|
||||
"employee_name": employee.employee_name,
|
||||
"leave_type": "_Test Leave Type Carry Forward",
|
||||
"from_date": nowdate(),
|
||||
"to_date": add_months(nowdate(),-12),
|
||||
"new_leaves_allocated": 10
|
||||
})
|
||||
doc.save()
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Leave Allocation",
|
||||
"__islocal": 1,
|
||||
"employee": employee.name,
|
||||
"employee_name": employee.employee_name,
|
||||
"leave_type": "_Test Leave Type Carry Forward",
|
||||
"from_date": nowdate(),
|
||||
"to_date": add_months(now_date(),12),
|
||||
"carry_forward": 1
|
||||
})
|
||||
doc.save()
|
||||
self.assertEquals(doc.total_leaves_allocated, 10)
|
||||
leave_type = create_leave_type(
|
||||
leave_type_name="_Test Carry Forward",
|
||||
is_carry_forward=1,
|
||||
carry_forward_leave_expiry=366)
|
||||
leave_type.submit()
|
||||
|
||||
leave_allocation = create_leave_allocation(
|
||||
from_date=add_months(nowdate(), -12),
|
||||
to_date=add_days(nowdate(), -1),
|
||||
leave_type=leave_type
|
||||
)
|
||||
leave_allocation.new_leaves_allocated = 10
|
||||
leave_allocation.submit()
|
||||
|
||||
carry_forward_alloc = create_leave_allocation(leave_type=leave_type)
|
||||
carry_forward_alloc.carry_forward = 1
|
||||
carry_forward_alloc.save()
|
||||
self.assertEquals(carry_forward_alloc.total_leaves_allocated, 10)
|
||||
|
||||
def create_leave_allocation(**args):
|
||||
args = frappe._dict(args)
|
||||
if not frappe.db.exists("Leave Type", "_Test Leave Type"):
|
||||
leave_type = create_leave_type(args.leave_type)
|
||||
leave_type.insert()
|
||||
|
||||
employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0])
|
||||
leave_allocation = frappe.get_doc({
|
||||
@ -108,10 +99,9 @@ def create_leave_allocation(**args):
|
||||
"__islocal": 1,
|
||||
"employee": employee.name,
|
||||
"employee_name": employee.employee_name,
|
||||
"leave_type": args.leave_type or "_Test Leave Type",
|
||||
"leave_type": args.leave_type.leave_type_name or "_Test Leave Type",
|
||||
"from_date": args.from_date or nowdate(),
|
||||
"to_date": args.to_date or add_months(nowdate(), 12),
|
||||
"new_leaves_allocated": args.new_leaves_allocated or 20
|
||||
"to_date": args.to_date or add_months(nowdate(), 12)
|
||||
})
|
||||
return leave_allocation
|
||||
|
||||
|
@ -8,6 +8,7 @@ from frappe import _
|
||||
test_records = frappe.get_test_records('Leave Type')
|
||||
|
||||
def create_leave_type(**args):
|
||||
args = frappe._dict(args)
|
||||
if frappe.db.exists("Leave Type", args.leave_type_name):
|
||||
return frappe.get_doc("Leave Type", args.leave_type_name)
|
||||
leave_type = frappe.get_doc({
|
||||
@ -18,7 +19,7 @@ def create_leave_type(**args):
|
||||
"is_earned_leave": args.is_earned_leave or 0,
|
||||
"is_lwp": args.is_lwp or 0,
|
||||
"is_carry_forward": args.is_carry_forward or 0,
|
||||
"carry_forward_leave_expiry": args.is_carry_forward or 0,
|
||||
"carry_forward_leave_expiry": args.carry_forward_leave_expiry or 0,
|
||||
"encashment_threshold_days": args.encashment_threshold_days or 5,
|
||||
"earning_component": "Leave Encashment"
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user