Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ability to schedule onboarding and separation activities #26738

Merged
merged 8 commits into from
Aug 27, 2021
45 changes: 42 additions & 3 deletions erpnext/controllers/employee_boarding_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from frappe import _
from frappe.desk.form import assign_to
from frappe.model.document import Document
from frappe.utils import flt, unique
from frappe.utils import flt, unique, add_days
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee

class EmployeeBoardingController(Document):
'''
Expand Down Expand Up @@ -41,18 +43,24 @@ def on_submit(self):

def create_task_and_notify_user(self):
# create the task for the given project and assign to the concerned person
holiday_list = self.get_holiday_list()

for activity in self.activities:
if activity.task:
continue

dates = self.get_task_dates(activity, holiday_list)

task = frappe.get_doc({
'doctype': 'Task',
'project': self.project,
'subject': activity.activity_name + ' : ' + self.employee_name,
'description': activity.description,
'department': self.department,
'company': self.company,
'task_weight': activity.task_weight
'task_weight': activity.task_weight,
'exp_start_date': dates[0],
'exp_end_date': dates[1]
}).insert(ignore_permissions=True)
activity.db_set('task', task.name)

Expand All @@ -79,6 +87,36 @@ def create_task_and_notify_user(self):
if users:
self.assign_task_to_users(task, users)

def get_holiday_list(self):
if self.doctype == 'Employee Separation':
return get_holiday_list_for_employee(self.employee)
else:
if self.employee:
return get_holiday_list_for_employee(self.employee)
else:
if not self.holiday_list:
frappe.throw(_('Please set the Holiday List.'), frappe.MandatoryError)
else:
return self.holiday_list

def get_task_dates(self, activity, holiday_list):
start_date = end_date = None

if activity.begin_on:
start_date = add_days(self.boarding_begins_on, activity.begin_on)
start_date = self.update_if_holiday(start_date, holiday_list)

if activity.duration:
end_date = add_days(self.boarding_begins_on, activity.begin_on + activity.duration)
end_date = self.update_if_holiday(end_date, holiday_list)

return [start_date, end_date]

def update_if_holiday(self, date, holiday_list):
while is_holiday(holiday_list, date):
date = add_days(date, 1)
return date

def assign_task_to_users(self, task, users):
for user in users:
args = {
Expand All @@ -103,7 +141,8 @@ def on_cancel(self):
@frappe.whitelist()
def get_onboarding_details(parent, parenttype):
return frappe.get_all('Employee Boarding Activity',
fields=['activity_name', 'role', 'user', 'required_for_employee_creation', 'description', 'task_weight'],
fields=['activity_name', 'role', 'user', 'required_for_employee_creation',
'description', 'task_weight', 'begin_on', 'duration'],
filters={'parent': parent, 'parenttype': parenttype},
order_by= 'idx')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actions": [],
"creation": "2018-05-09 05:37:18.439763",
"doctype": "DocType",
"editable_grid": 1,
Expand All @@ -7,6 +8,8 @@
"activity_name",
"user",
"role",
"begin_on",
"duration",
"column_break_3",
"task",
"task_weight",
Expand All @@ -16,22 +19,27 @@
],
"fields": [
{
"columns": 3,
"fieldname": "activity_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Activity Name"
"label": "Activity Name",
"reqd": 1
},
{
"columns": 2,
"depends_on": "eval:!doc.role",
"fieldname": "user",
"fieldtype": "Link",
"in_list_view": 1,
"label": "User",
"options": "User"
},
{
"columns": 1,
"depends_on": "eval:!doc.user",
"fieldname": "role",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Role",
"options": "Role"
},
Expand Down Expand Up @@ -67,10 +75,25 @@
"fieldname": "description",
"fieldtype": "Text Editor",
"label": "Description"
},
{
"columns": 2,
"fieldname": "duration",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Duration (Days)"
},
{
"columns": 2,
"fieldname": "begin_on",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Begin On (Days)"
}
],
"istable": 1,
"modified": "2019-06-03 19:22:42.965762",
"links": [],
"modified": "2021-07-30 15:55:22.470102",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Boarding Activity",
Expand Down
50 changes: 39 additions & 11 deletions erpnext/hr/doctype/employee_onboarding/employee_onboarding.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
"field_order": [
"job_applicant",
"job_offer",
"employee_name",
"employee",
"date_of_joining",
"boarding_status",
"notify_users_by_email",
"column_break_7",
"employee_onboarding_template",
"column_break_7",
"company",
"boarding_status",
"project",
"details_section",
"employee",
"employee_name",
"department",
"designation",
"employee_grade",
"project",
"holiday_list",
"column_break_13",
"date_of_joining",
"boarding_begins_on",
"table_for_activity",
"activities",
"notify_users_by_email",
"amended_from"
],
"fields": [
Expand Down Expand Up @@ -58,7 +62,8 @@
"fieldname": "date_of_joining",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Date of Joining"
"label": "Date of Joining",
"reqd": 1
},
{
"allow_on_submit": 1,
Expand Down Expand Up @@ -90,7 +95,8 @@
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company"
"options": "Company",
"reqd": 1
},
{
"fieldname": "department",
Expand Down Expand Up @@ -121,7 +127,8 @@
},
{
"fieldname": "table_for_activity",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Onboarding Activities"
},
{
"allow_on_submit": 1,
Expand All @@ -138,11 +145,32 @@
"options": "Employee Onboarding",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "details_section",
"fieldtype": "Section Break",
"label": "Employee Details"
},
{
"fieldname": "column_break_13",
"fieldtype": "Column Break"
},
{
"fieldname": "boarding_begins_on",
"fieldtype": "Date",
"label": "Onboarding Begins On",
"reqd": 1
},
{
"fieldname": "holiday_list",
"fieldtype": "Link",
"label": "Holiday List",
"options": "Holiday List"
}
],
"is_submittable": 1,
"links": [],
"modified": "2021-06-03 18:01:51.097927",
"modified": "2021-07-30 14:55:04.560683",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Onboarding",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import frappe
import unittest
from frappe.utils import nowdate
from frappe.utils import getdate
from erpnext.hr.doctype.employee_onboarding.employee_onboarding import make_employee
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
from erpnext.hr.doctype.employee_onboarding.employee_onboarding import IncompleteTaskError
from erpnext.hr.doctype.job_offer.test_job_offer import create_job_offer

Expand Down Expand Up @@ -46,7 +47,7 @@ def test_employee_onboarding_incomplete_task(self):
onboarding.reload()
employee = make_employee(onboarding.name)
employee.first_name = employee.employee_name
employee.date_of_joining = nowdate()
employee.date_of_joining = getdate()
employee.date_of_birth = '1990-05-08'
employee.gender = 'Female'
employee.insert()
Expand Down Expand Up @@ -82,11 +83,14 @@ def get_job_offer(applicant_name):
def create_employee_onboarding():
applicant = get_job_applicant()
job_offer = get_job_offer(applicant.name)
holiday_list = make_holiday_list()

onboarding = frappe.new_doc('Employee Onboarding')
onboarding.job_applicant = applicant.name
onboarding.job_offer = job_offer.name
onboarding.date_of_joining = onboarding.boarding_begins_on = getdate()
onboarding.company = '_Test Company'
onboarding.holiday_list = holiday_list
onboarding.designation = 'Researcher'
onboarding.append('activities', {
'activity_name': 'Assign ID Card',
Expand Down
Empty file.
Loading