[fix] Test case fixed
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
index 43facf6..57eb146 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
@@ -9,6 +9,12 @@
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 @@
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 @@
.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 @@
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 @@
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):
diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
index d36fb2c..b3eee31 100644
--- a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
@@ -13,7 +13,7 @@
"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 @@
"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
}
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 40f2136..1d84a40 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -49,6 +49,8 @@
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 @@
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):
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 2bb7f52..fb69440 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -10,8 +10,20 @@
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)
diff --git a/test_sites/apps.txt b/test_sites/apps.txt
new file mode 100644
index 0000000..ee64549
--- /dev/null
+++ b/test_sites/apps.txt
@@ -0,0 +1 @@
+erpnext
\ No newline at end of file
diff --git a/test_sites/languages.txt b/test_sites/languages.txt
new file mode 100644
index 0000000..cf2b150
--- /dev/null
+++ b/test_sites/languages.txt
@@ -0,0 +1 @@
+en english
\ No newline at end of file
diff --git a/test_sites/test_site/site_config.json b/test_sites/test_site/site_config.json
new file mode 100644
index 0000000..48b330b
--- /dev/null
+++ b/test_sites/test_site/site_config.json
@@ -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"]
+}
\ No newline at end of file