fix: boarding status in Employee Onboarding and Separation
- make boarding status read-only as its dependent on project - update boarding status in onboarding/separation on project update - update tests to check status changes
This commit is contained in:
parent
3d5e15284b
commit
67519d6b79
@ -50,21 +50,6 @@ frappe.ui.form.on('Employee Onboarding', {
|
||||
}, __('Create'));
|
||||
frm.page.set_inner_btn_group_as_primary(__('Create'));
|
||||
}
|
||||
if (frm.doc.docstatus === 1 && frm.doc.project) {
|
||||
frappe.call({
|
||||
method: "erpnext.hr.utils.get_boarding_status",
|
||||
args: {
|
||||
"project": frm.doc.project
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
frm.set_value('boarding_status', r.message);
|
||||
}
|
||||
refresh_field("boarding_status");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
employee_onboarding_template: function(frm) {
|
||||
|
@ -30,18 +30,14 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Job Applicant",
|
||||
"options": "Job Applicant",
|
||||
"reqd": 1,
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "job_offer",
|
||||
"fieldtype": "Link",
|
||||
"label": "Job Offer",
|
||||
"options": "Job Offer",
|
||||
"reqd": 1,
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "job_applicant.applicant_name",
|
||||
@ -49,116 +45,90 @@
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Employee Name",
|
||||
"reqd": 1,
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "employee",
|
||||
"fieldtype": "Link",
|
||||
"label": "Employee",
|
||||
"options": "Employee",
|
||||
"read_only": 1,
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "date_of_joining",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "Date of Joining",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"label": "Date of Joining"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"default": "Pending",
|
||||
"fieldname": "boarding_status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Status",
|
||||
"options": "\nPending\nIn Process\nCompleted",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Pending\nIn Process\nCompleted",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"default": "0",
|
||||
"fieldname": "notify_users_by_email",
|
||||
"fieldtype": "Check",
|
||||
"label": "Notify users by email",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"label": "Notify users by email"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_7",
|
||||
"fieldtype": "Column Break",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "employee_onboarding_template",
|
||||
"fieldtype": "Link",
|
||||
"label": "Employee Onboarding Template",
|
||||
"options": "Employee Onboarding Template",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Employee Onboarding Template"
|
||||
},
|
||||
{
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"label": "Company",
|
||||
"options": "Company",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Company"
|
||||
},
|
||||
{
|
||||
"fieldname": "department",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Department",
|
||||
"options": "Department",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Department"
|
||||
},
|
||||
{
|
||||
"fieldname": "designation",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Designation",
|
||||
"options": "Designation",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Designation"
|
||||
},
|
||||
{
|
||||
"fieldname": "employee_grade",
|
||||
"fieldtype": "Link",
|
||||
"label": "Employee Grade",
|
||||
"options": "Employee Grade",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Employee Grade"
|
||||
},
|
||||
{
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"label": "Project",
|
||||
"options": "Project",
|
||||
"read_only": 1,
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "table_for_activity",
|
||||
"fieldtype": "Section Break",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"fieldname": "activities",
|
||||
"fieldtype": "Table",
|
||||
"label": "Activities",
|
||||
"options": "Employee Boarding Activity",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"options": "Employee Boarding Activity"
|
||||
},
|
||||
{
|
||||
"fieldname": "amended_from",
|
||||
@ -167,14 +137,12 @@
|
||||
"no_copy": 1,
|
||||
"options": "Employee Onboarding",
|
||||
"print_hide": 1,
|
||||
"read_only": 1,
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-06-25 15:22:24.923835",
|
||||
"modified": "2021-06-03 18:01:51.097927",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Employee Onboarding",
|
||||
|
@ -11,39 +11,26 @@ from erpnext.hr.doctype.employee_onboarding.employee_onboarding import Incomplet
|
||||
from erpnext.hr.doctype.job_offer.test_job_offer import create_job_offer
|
||||
|
||||
class TestEmployeeOnboarding(unittest.TestCase):
|
||||
def test_employee_onboarding_incomplete_task(self):
|
||||
def setUp(self):
|
||||
if frappe.db.exists('Employee Onboarding', {'employee_name': 'Test Researcher'}):
|
||||
frappe.delete_doc('Employee Onboarding', {'employee_name': 'Test Researcher'})
|
||||
_set_up()
|
||||
applicant = get_job_applicant()
|
||||
|
||||
job_offer = create_job_offer(job_applicant=applicant.name)
|
||||
job_offer.submit()
|
||||
project = "Employee Onboarding : Test Researcher - test@researcher.com"
|
||||
frappe.db.sql("delete from tabProject where name=%s", project)
|
||||
frappe.db.sql("delete from tabTask where project=%s", project)
|
||||
|
||||
onboarding = frappe.new_doc('Employee Onboarding')
|
||||
onboarding.job_applicant = applicant.name
|
||||
onboarding.job_offer = job_offer.name
|
||||
onboarding.company = '_Test Company'
|
||||
onboarding.designation = 'Researcher'
|
||||
onboarding.append('activities', {
|
||||
'activity_name': 'Assign ID Card',
|
||||
'role': 'HR User',
|
||||
'required_for_employee_creation': 1
|
||||
})
|
||||
onboarding.append('activities', {
|
||||
'activity_name': 'Assign a laptop',
|
||||
'role': 'HR User'
|
||||
})
|
||||
onboarding.status = 'Pending'
|
||||
onboarding.insert()
|
||||
onboarding.submit()
|
||||
def test_employee_onboarding_incomplete_task(self):
|
||||
onboarding = create_employee_onboarding()
|
||||
|
||||
project_name = frappe.db.get_value("Project", onboarding.project, "project_name")
|
||||
project_name = frappe.db.get_value('Project', onboarding.project, 'project_name')
|
||||
self.assertEqual(project_name, 'Employee Onboarding : Test Researcher - test@researcher.com')
|
||||
|
||||
# don't allow making employee if onboarding is not complete
|
||||
self.assertRaises(IncompleteTaskError, make_employee, onboarding.name)
|
||||
|
||||
# boarding status
|
||||
self.assertEqual(onboarding.boarding_status, 'Pending')
|
||||
|
||||
# complete the task
|
||||
project = frappe.get_doc('Project', onboarding.project)
|
||||
for task in frappe.get_all('Task', dict(project=project.name)):
|
||||
@ -51,6 +38,10 @@ class TestEmployeeOnboarding(unittest.TestCase):
|
||||
task.status = 'Completed'
|
||||
task.save()
|
||||
|
||||
# boarding status
|
||||
onboarding.reload()
|
||||
self.assertEqual(onboarding.boarding_status, 'Completed')
|
||||
|
||||
# make employee
|
||||
onboarding.reload()
|
||||
employee = make_employee(onboarding.name)
|
||||
@ -61,6 +52,13 @@ class TestEmployeeOnboarding(unittest.TestCase):
|
||||
employee.insert()
|
||||
self.assertEqual(employee.employee_name, 'Test Researcher')
|
||||
|
||||
def tearDown(self):
|
||||
for entry in frappe.get_all('Employee Onboarding'):
|
||||
doc = frappe.get_doc('Employee Onboarding', entry.name)
|
||||
doc.cancel()
|
||||
doc.delete()
|
||||
|
||||
|
||||
def get_job_applicant():
|
||||
if frappe.db.exists('Job Applicant', 'Test Researcher - test@researcher.com'):
|
||||
return frappe.get_doc('Job Applicant', 'Test Researcher - test@researcher.com')
|
||||
@ -72,10 +70,35 @@ def get_job_applicant():
|
||||
applicant.insert()
|
||||
return applicant
|
||||
|
||||
def _set_up():
|
||||
for doctype in ["Employee Onboarding"]:
|
||||
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
|
||||
def get_job_offer(applicant_name):
|
||||
job_offer = frappe.db.exists('Job Offer', {'job_applicant': applicant_name})
|
||||
if job_offer:
|
||||
return frappe.get_doc('Job Offer', job_offer)
|
||||
|
||||
project = "Employee Onboarding : Test Researcher - test@researcher.com"
|
||||
frappe.db.sql("delete from tabProject where name=%s", project)
|
||||
frappe.db.sql("delete from tabTask where project=%s", project)
|
||||
job_offer = create_job_offer(job_applicant=applicant_name)
|
||||
job_offer.submit()
|
||||
return job_offer
|
||||
|
||||
def create_employee_onboarding():
|
||||
applicant = get_job_applicant()
|
||||
job_offer = get_job_offer(applicant.name)
|
||||
|
||||
onboarding = frappe.new_doc('Employee Onboarding')
|
||||
onboarding.job_applicant = applicant.name
|
||||
onboarding.job_offer = job_offer.name
|
||||
onboarding.company = '_Test Company'
|
||||
onboarding.designation = 'Researcher'
|
||||
onboarding.append('activities', {
|
||||
'activity_name': 'Assign ID Card',
|
||||
'role': 'HR User',
|
||||
'required_for_employee_creation': 1
|
||||
})
|
||||
onboarding.append('activities', {
|
||||
'activity_name': 'Assign a laptop',
|
||||
'role': 'HR User'
|
||||
})
|
||||
onboarding.status = 'Pending'
|
||||
onboarding.insert()
|
||||
onboarding.submit()
|
||||
|
||||
return onboarding
|
@ -23,20 +23,6 @@ frappe.ui.form.on('Employee Separation', {
|
||||
frappe.set_route('List', 'Task', {project: frm.doc.project});
|
||||
},__("View"));
|
||||
}
|
||||
if (frm.doc.docstatus === 1 && frm.doc.project) {
|
||||
frappe.call({
|
||||
method: "erpnext.hr.utils.get_boarding_status",
|
||||
args: {
|
||||
"project": frm.doc.project
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
frm.set_value('boarding_status', r.message);
|
||||
}
|
||||
refresh_field("boarding_status");
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
employee_separation_template: function(frm) {
|
||||
|
@ -50,11 +50,12 @@
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"default": "Pending",
|
||||
"fieldname": "boarding_status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Status",
|
||||
"options": "\nPending\nIn Process\nCompleted",
|
||||
"reqd": 1
|
||||
"options": "Pending\nIn Process\nCompleted",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
@ -147,7 +148,7 @@
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-28 15:58:36.020196",
|
||||
"modified": "2021-06-03 18:02:54.007313",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Employee Separation",
|
||||
|
@ -6,21 +6,43 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
test_dependencies = ["Employee Onboarding"]
|
||||
test_dependencies = ['Employee Onboarding']
|
||||
|
||||
class TestEmployeeSeparation(unittest.TestCase):
|
||||
def test_employee_separation(self):
|
||||
employee = frappe.db.get_value("Employee", {"status": "Active"})
|
||||
separation = frappe.new_doc('Employee Separation')
|
||||
separation.employee = employee
|
||||
separation.company = '_Test Company'
|
||||
separation.append('activities', {
|
||||
'activity_name': 'Deactivate Employee',
|
||||
'role': 'HR User'
|
||||
})
|
||||
separation.boarding_status = 'Pending'
|
||||
separation.insert()
|
||||
separation.submit()
|
||||
separation = create_employee_separation()
|
||||
|
||||
self.assertEqual(separation.docstatus, 1)
|
||||
self.assertEqual(separation.boarding_status, 'Pending')
|
||||
|
||||
project = frappe.get_doc('Project', separation.project)
|
||||
project.percent_complete_method = 'Manual'
|
||||
project.status = 'Completed'
|
||||
project.save()
|
||||
|
||||
separation.reload()
|
||||
self.assertEqual(separation.boarding_status, 'Completed')
|
||||
|
||||
separation.cancel()
|
||||
self.assertEqual(separation.project, "")
|
||||
self.assertEqual(separation.project, '')
|
||||
|
||||
def tearDown(self):
|
||||
for entry in frappe.get_all('Employee Separation'):
|
||||
doc = frappe.get_doc('Employee Separation', entry.name)
|
||||
if doc.docstatus == 1:
|
||||
doc.cancel()
|
||||
doc.delete()
|
||||
|
||||
def create_employee_separation():
|
||||
employee = frappe.db.get_value('Employee', {'status': 'Active'})
|
||||
separation = frappe.new_doc('Employee Separation')
|
||||
separation.employee = employee
|
||||
separation.company = '_Test Company'
|
||||
separation.append('activities', {
|
||||
'activity_name': 'Deactivate Employee',
|
||||
'role': 'HR User'
|
||||
})
|
||||
separation.boarding_status = 'Pending'
|
||||
separation.insert()
|
||||
separation.submit()
|
||||
return separation
|
@ -114,16 +114,23 @@ def get_onboarding_details(parent, parenttype):
|
||||
filters={"parent": parent, "parenttype": parenttype},
|
||||
order_by= "idx")
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_boarding_status(project):
|
||||
def update_employee_boarding_status(project):
|
||||
employee_onboarding = frappe.db.exists('Employee Onboarding', {'project': project.name})
|
||||
employee_separation = frappe.db.exists('Employee Separation', {'project': project.name})
|
||||
|
||||
if not (employee_onboarding or employee_separation):
|
||||
return
|
||||
|
||||
status = 'Pending'
|
||||
if project:
|
||||
doc = frappe.get_doc('Project', project)
|
||||
if flt(doc.percent_complete) > 0.0 and flt(doc.percent_complete) < 100.0:
|
||||
status = 'In Process'
|
||||
elif flt(doc.percent_complete) == 100.0:
|
||||
status = 'Completed'
|
||||
return status
|
||||
if flt(project.percent_complete) > 0.0 and flt(project.percent_complete) < 100.0:
|
||||
status = 'In Process'
|
||||
elif flt(project.percent_complete) == 100.0:
|
||||
status = 'Completed'
|
||||
|
||||
if employee_onboarding:
|
||||
frappe.db.set_value('Employee Onboarding', employee_onboarding, 'boarding_status', status)
|
||||
elif employee_separation:
|
||||
frappe.db.set_value('Employee Separation', employee_separation, 'boarding_status', status)
|
||||
|
||||
def set_employee_name(doc):
|
||||
if doc.employee and not doc.employee_name:
|
||||
|
@ -14,6 +14,7 @@ from erpnext.hr.doctype.daily_work_summary.daily_work_summary import get_users_e
|
||||
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
||||
from frappe.model.document import Document
|
||||
from erpnext.education.doctype.student_attendance.student_attendance import get_holiday_list
|
||||
from erpnext.hr.utils import update_employee_boarding_status
|
||||
|
||||
class Project(Document):
|
||||
def get_feed(self):
|
||||
@ -37,6 +38,7 @@ class Project(Document):
|
||||
self.send_welcome_email()
|
||||
self.update_costing()
|
||||
self.update_percent_complete()
|
||||
update_employee_boarding_status(self)
|
||||
|
||||
def copy_from_template(self):
|
||||
'''
|
||||
@ -132,6 +134,7 @@ class Project(Document):
|
||||
def update_project(self):
|
||||
'''Called externally by Task'''
|
||||
self.update_percent_complete()
|
||||
update_employee_boarding_status(self)
|
||||
self.update_costing()
|
||||
self.db_update()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user