[fix] Test case fixed

This commit is contained in:
Nabin Hait 2015-11-16 15:35:09 +05:30
parent 58c4646199
commit b6de519571
7 changed files with 45 additions and 10 deletions

View File

@ -9,6 +9,12 @@ from frappe.model.document import Document
from erpnext.hr.utils import set_employee_name
from erpnext.hr.doctype.leave_application.leave_application import get_approved_leaves_for_period
class OverlapError(frappe.ValidationError): pass
class BackDatedAllocationError(frappe.ValidationError): pass
class OverAllocationError(frappe.ValidationError): pass
class LessAllocationError(frappe.ValidationError): pass
class ValueMultiplierError(frappe.ValidationError): pass
class LeaveAllocation(Document):
def validate(self):
self.validate_period()
@ -35,7 +41,7 @@ class LeaveAllocation(Document):
def validate_new_leaves_allocated_value(self):
"""validate that leave allocation is in multiples of 0.5"""
if flt(self.new_leaves_allocated) % 0.5:
frappe.throw(_("Leaves must be allocated in multiples of 0.5"))
frappe.throw(_("Leaves must be allocated in multiples of 0.5"), ValueMultiplierError)
def validate_allocation_overlap(self):
leave_allocation = frappe.db.sql("""
@ -49,7 +55,7 @@ class LeaveAllocation(Document):
.format(self.leave_type, self.employee, formatdate(self.from_date), formatdate(self.to_date)))
frappe.throw(_('Reference') + ': <a href="#Form/Leave Allocation/{0}">{0}</a>'
.format(leave_allocation[0][0]))
.format(leave_allocation[0][0]), OverlapError)
def validate_back_dated_allocation(self):
future_allocation = frappe.db.sql("""select name, from_date from `tabLeave Allocation`
@ -58,7 +64,8 @@ class LeaveAllocation(Document):
if future_allocation:
frappe.throw(_("Leave cannot be allocated before {0}, as leave balance has already been carry-forwarded in the future leave allocation record {1}")
.format(formatdate(future_allocation[0].from_date), future_allocation[0].name))
.format(formatdate(future_allocation[0].from_date), future_allocation[0].name),
BackDatedAllocationError)
def set_total_leaves_allocated(self):
self.carry_forwarded_leaves = get_carry_forwarded_leaves(self.employee,
@ -71,14 +78,14 @@ class LeaveAllocation(Document):
def validate_total_leaves_allocated(self):
if date_diff(self.to_date, self.from_date) <= flt(self.total_leaves_allocated):
frappe.throw(_("Total allocated leaves are more than days in the period"))
frappe.throw(_("Total allocated leaves are more than days in the period"), OverAllocationError)
def validate_against_leave_applications(self):
leaves_taken = get_approved_leaves_for_period(self.employee, self.leave_type,
self.from_date, self.to_date)
if flt(leaves_taken) > flt(self.total_leaves_allocated):
frappe.throw(_("Total allocated leaves {0} cannot be less than already approved leaves {1} for the period").format(self.total_leaves_allocated, leaves_taken))
frappe.throw(_("Total allocated leaves {0} cannot be less than already approved leaves {1} for the period").format(self.total_leaves_allocated, leaves_taken), LessAllocationError)
@frappe.whitelist()
def get_carry_forwarded_leaves(employee, leave_type, date, carry_forward=None):

View File

@ -13,7 +13,7 @@ class TestLeaveAllocation(unittest.TestCase):
"employee": employee.name,
"employee_name": employee.employee_name,
"leave_type": "_Test Leave Type",
"from_date": getdate("2015-10-1"),
"from_date": getdate("2015-10-01"),
"to_date": getdate("2015-10-31"),
"new_leaves_allocated": 5,
"docstatus": 1
@ -24,7 +24,7 @@ class TestLeaveAllocation(unittest.TestCase):
"employee": employee.name,
"employee_name": employee.employee_name,
"leave_type": "_Test Leave Type",
"from_date": getdate("2015-09-1"),
"from_date": getdate("2015-09-01"),
"to_date": getdate("2015-11-30"),
"new_leaves_allocated": 5
}

View File

@ -49,6 +49,8 @@ class LeaveApplication(Document):
def on_submit(self):
if self.status != "Approved":
frappe.throw(_("Only Leave Applications with status 'Approved' can be submitted"))
self.validate_back_dated_application()
# notify leave applier about approval
self.notify_employee(self.status)
@ -87,7 +89,7 @@ class LeaveApplication(Document):
and carry_forward=1""", (self.employee, self.leave_type, self.to_date), as_dict=1)
if future_allocation:
frappe.throw(_("Leave cannot be applied before {0}, as leave balance has already been carry-forwarded in the future leave allocation record {1}")
frappe.throw(_("Leave cannot be applied/cancelled before {0}, as leave balance has already been carry-forwarded in the future leave allocation record {1}")
.format(formatdate(future_allocation[0].from_date), future_allocation[0].name))
def show_block_day_warning(self):

View File

@ -10,8 +10,20 @@ from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_sli
class TestSalarySlip(unittest.TestCase):
def setUp(self):
frappe.db.sql("""delete from `tabLeave Application`""")
frappe.db.sql("""delete from `tabSalary Slip`""")
for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
frappe.db.sql("delete from `tab%s`" % dt)
allocation = frappe.get_doc({
"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)

1
test_sites/apps.txt Normal file
View File

@ -0,0 +1 @@
erpnext

1
test_sites/languages.txt Normal file
View File

@ -0,0 +1 @@
en english

View File

@ -0,0 +1,12 @@
{
"db_name": "test_frappe",
"db_password": "test_frappe",
"auto_email_id": "test@example.com",
"mail_server": "smtp.example.com",
"mail_login": "test@example.com",
"mail_password": "test",
"admin_password": "admin",
"run_selenium_tests": 1,
"host_name": "http://localhost:8000",
"install_apps": ["erpnext"]
}