Fixes in test cases
This commit is contained in:
parent
45a3226645
commit
648062d071
@ -45,6 +45,9 @@ doc_events = {
|
|||||||
"Stock Entry": {
|
"Stock Entry": {
|
||||||
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_qty",
|
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_qty",
|
||||||
"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_qty"
|
"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_qty"
|
||||||
|
},
|
||||||
|
"User": {
|
||||||
|
"on_update": "erpnext.hr.doctype.employee.employee.update_user_default"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +52,7 @@ class Employee(Document):
|
|||||||
self.validate_duplicate_user_id()
|
self.validate_duplicate_user_id()
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
if self.user_id and frappe.db.get_value("User", self.user_id, 'docstatus') == 0:
|
if self.user_id:
|
||||||
self.restrict_user()
|
|
||||||
self.update_user_default()
|
self.update_user_default()
|
||||||
self.update_user()
|
self.update_user()
|
||||||
|
|
||||||
@ -65,6 +64,7 @@ class Employee(Document):
|
|||||||
self.add_restriction_if_required("Employee", self.user_id)
|
self.add_restriction_if_required("Employee", self.user_id)
|
||||||
|
|
||||||
def update_user_default(self):
|
def update_user_default(self):
|
||||||
|
self.restrict_user()
|
||||||
frappe.db.set_default("employee_name", self.employee_name, self.user_id)
|
frappe.db.set_default("employee_name", self.employee_name, self.user_id)
|
||||||
frappe.db.set_default("company", self.company, self.user_id)
|
frappe.db.set_default("company", self.company, self.user_id)
|
||||||
|
|
||||||
@ -228,3 +228,11 @@ def make_salary_structure(source_name, target=None):
|
|||||||
})
|
})
|
||||||
target.make_earn_ded_table()
|
target.make_earn_ded_table()
|
||||||
return target
|
return target
|
||||||
|
|
||||||
|
def update_user_default(doc, method):
|
||||||
|
# called via User hook
|
||||||
|
try:
|
||||||
|
employee = frappe.get_doc("Employee", {"user_id": doc.name})
|
||||||
|
employee.update_user_default()
|
||||||
|
except frappe.DoesNotExistError:
|
||||||
|
pass
|
||||||
|
@ -5,6 +5,7 @@ import frappe
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from erpnext.hr.doctype.leave_application.leave_application import LeaveDayBlockedError, OverlapError
|
from erpnext.hr.doctype.leave_application.leave_application import LeaveDayBlockedError, OverlapError
|
||||||
|
from frappe.core.page.user_properties.user_properties import clear_restrictions
|
||||||
|
|
||||||
test_dependencies = ["Leave Allocation", "Leave Block List"]
|
test_dependencies = ["Leave Allocation", "Leave Block List"]
|
||||||
|
|
||||||
@ -67,6 +68,18 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
employee.save()
|
employee.save()
|
||||||
frappe.set_user(temp_session_user)
|
frappe.set_user(temp_session_user)
|
||||||
|
|
||||||
|
def _remove_employee_leave_approver(self, employee, leave_approver):
|
||||||
|
temp_session_user = frappe.session.user
|
||||||
|
frappe.set_user("Administrator")
|
||||||
|
employee = frappe.get_doc("Employee", employee)
|
||||||
|
d = employee.get("employee_leave_approvers", {
|
||||||
|
"leave_approver": leave_approver
|
||||||
|
})
|
||||||
|
if d:
|
||||||
|
employee.get("employee_leave_approvers").remove(d[0])
|
||||||
|
employee.save()
|
||||||
|
frappe.set_user(temp_session_user)
|
||||||
|
|
||||||
def get_application(self, doc):
|
def get_application(self, doc):
|
||||||
application = frappe.copy_doc(doc)
|
application = frappe.copy_doc(doc)
|
||||||
application.from_date = "2013-01-01"
|
application.from_date = "2013-01-01"
|
||||||
@ -78,6 +91,7 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
|
|
||||||
from frappe.utils.user import add_role
|
from frappe.utils.user import add_role
|
||||||
add_role("test1@example.com", "HR User")
|
add_role("test1@example.com", "HR User")
|
||||||
|
clear_restrictions("Employee")
|
||||||
|
|
||||||
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")
|
||||||
@ -154,6 +168,8 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
def _test_leave_approval_basic_case(self):
|
def _test_leave_approval_basic_case(self):
|
||||||
self._clear_applications()
|
self._clear_applications()
|
||||||
|
|
||||||
|
self._add_employee_leave_approver("_T-Employee-0001", "test1@example.com")
|
||||||
|
|
||||||
# create leave application as Employee
|
# create leave application as Employee
|
||||||
frappe.set_user("test@example.com")
|
frappe.set_user("test@example.com")
|
||||||
application = self.get_application(_test_records[0])
|
application = self.get_application(_test_records[0])
|
||||||
@ -175,8 +191,8 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
# add a different leave approver in the employee's list
|
# add a different leave approver in the employee's list
|
||||||
# should raise exception if not a valid leave approver
|
# should raise exception if not a valid leave approver
|
||||||
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")
|
||||||
|
|
||||||
# TODO - add test2@example.com leave approver in employee's leave approvers list
|
|
||||||
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")
|
||||||
|
|
||||||
|
@ -5,6 +5,10 @@ import frappe, unittest
|
|||||||
|
|
||||||
class TimeLogBatchTest(unittest.TestCase):
|
class TimeLogBatchTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
for name in frappe.db.sql_list("select name from `tabTime Log Batch` where docstatus=1"):
|
||||||
|
frappe.get_doc("Time Log Batch", name).cancel()
|
||||||
|
frappe.delete_doc("Time Log Batch", name)
|
||||||
|
|
||||||
for name in frappe.db.sql_list("select name from `tabTime Log` where docstatus=1"):
|
for name in frappe.db.sql_list("select name from `tabTime Log` where docstatus=1"):
|
||||||
frappe.get_doc("Time Log", name).cancel()
|
frappe.get_doc("Time Log", name).cancel()
|
||||||
frappe.delete_doc("Time Log", name)
|
frappe.delete_doc("Time Log", name)
|
||||||
|
Loading…
Reference in New Issue
Block a user