fix: job applicant fixes (#22448)

* fix(validation): not two job offer should be allowed for single job_applicant

* fix: don't allow to create employee_onboarding without job offer

* fix: server side validation

* fix: requested changes
This commit is contained in:
Anurag Mishra
2020-07-23 12:22:42 +05:30
committed by GitHub
parent 7ac4ad8410
commit 453325fbc9
5 changed files with 206 additions and 600 deletions

View File

@@ -8,10 +8,20 @@ frappe.ui.form.on('Employee Onboarding', {
frm.add_fetch("employee_onboarding_template", "designation", "designation"); frm.add_fetch("employee_onboarding_template", "designation", "designation");
frm.add_fetch("employee_onboarding_template", "employee_grade", "employee_grade"); frm.add_fetch("employee_onboarding_template", "employee_grade", "employee_grade");
frm.set_query("job_applicant", function () {
return {
filters:{
"status": "Accepted",
}
};
});
frm.set_query('job_offer', function () { frm.set_query('job_offer', function () {
return { return {
filters: { filters: {
'job_applicant': frm.doc.job_applicant 'job_applicant': frm.doc.job_applicant,
'docstatus': 1
} }
}; };
}); });

View File

@@ -1,620 +1,203 @@
{ {
"allow_copy": 0, "actions": [],
"allow_guest_to_view": 0, "autoname": "HR-EMP-ONB-.YYYY.-.#####",
"allow_import": 0, "creation": "2018-05-09 04:57:20.016220",
"allow_rename": 0, "doctype": "DocType",
"autoname": "HR-EMP-ONB-.YYYY.-.#####", "editable_grid": 1,
"beta": 0, "engine": "InnoDB",
"creation": "2018-05-09 04:57:20.016220", "field_order": [
"custom": 0, "job_applicant",
"docstatus": 0, "job_offer",
"doctype": "DocType", "employee_name",
"document_type": "", "employee",
"editable_grid": 1, "date_of_joining",
"engine": "InnoDB", "boarding_status",
"notify_users_by_email",
"column_break_7",
"employee_onboarding_template",
"company",
"department",
"designation",
"employee_grade",
"project",
"table_for_activity",
"activities",
"amended_from"
],
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0, "fieldname": "job_applicant",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 0, "label": "Job Applicant",
"bold": 0, "options": "Job Applicant",
"collapsible": 0, "reqd": 1,
"columns": 0, "show_days": 1,
"fieldname": "job_applicant", "show_seconds": 1
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Job Applicant",
"length": 0,
"no_copy": 0,
"options": "Job Applicant",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "job_offer",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Job Offer",
"length": 0,
"no_copy": 0,
"options": "Job Offer",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_from": "job_applicant.applicant_name",
"fieldname": "employee_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Employee Name",
"length": 0,
"no_copy": 0,
"options": "",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "employee",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Employee",
"length": 0,
"no_copy": 0,
"options": "Employee",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "date_of_joining",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Date of Joining",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "boarding_status",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Status",
"length": 0,
"no_copy": 0,
"options": "\nPending\nIn Process\nCompleted",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0, "fieldname": "job_offer",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 1, "label": "Job Offer",
"bold": 0, "options": "Job Offer",
"collapsible": 0, "reqd": 1,
"columns": 0, "show_days": 1,
"fieldname": "notify_users_by_email", "show_seconds": 1
"fieldtype": "Check", },
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Notify users by email",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fetch_from": "job_applicant.applicant_name",
"allow_in_quick_entry": 0, "fieldname": "employee_name",
"allow_on_submit": 0, "fieldtype": "Data",
"bold": 0, "in_list_view": 1,
"collapsible": 0, "label": "Employee Name",
"columns": 0, "reqd": 1,
"fieldname": "column_break_7", "show_days": 1,
"fieldtype": "Column Break", "show_seconds": 1
"hidden": 0, },
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "employee",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 0, "label": "Employee",
"bold": 0, "options": "Employee",
"collapsible": 0, "read_only": 1,
"columns": 0, "show_days": 1,
"fieldname": "employee_onboarding_template", "show_seconds": 1
"fieldtype": "Link", },
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Employee Onboarding Template",
"length": 0,
"no_copy": 0,
"options": "Employee Onboarding Template",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "date_of_joining",
"allow_in_quick_entry": 0, "fieldtype": "Date",
"allow_on_submit": 0, "in_list_view": 1,
"bold": 0, "label": "Date of Joining",
"collapsible": 0, "show_days": 1,
"columns": 0, "show_seconds": 1
"fieldname": "company", },
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Company",
"length": 0,
"no_copy": 0,
"options": "Company",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "allow_on_submit": 1,
"allow_in_quick_entry": 0, "fieldname": "boarding_status",
"allow_on_submit": 0, "fieldtype": "Select",
"bold": 0, "label": "Status",
"collapsible": 0, "options": "\nPending\nIn Process\nCompleted",
"columns": 0, "show_days": 1,
"fieldname": "department", "show_seconds": 1
"fieldtype": "Link", },
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Department",
"length": 0,
"no_copy": 0,
"options": "Department",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "allow_on_submit": 1,
"allow_in_quick_entry": 0, "default": "0",
"allow_on_submit": 0, "fieldname": "notify_users_by_email",
"bold": 0, "fieldtype": "Check",
"collapsible": 0, "label": "Notify users by email",
"columns": 0, "show_days": 1,
"fieldname": "designation", "show_seconds": 1
"fieldtype": "Link", },
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Designation",
"length": 0,
"no_copy": 0,
"options": "Designation",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "column_break_7",
"allow_in_quick_entry": 0, "fieldtype": "Column Break",
"allow_on_submit": 0, "show_days": 1,
"bold": 0, "show_seconds": 1
"collapsible": 0, },
"columns": 0,
"fieldname": "employee_grade",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Employee Grade",
"length": 0,
"no_copy": 0,
"options": "Employee Grade",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "employee_onboarding_template",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 0, "label": "Employee Onboarding Template",
"bold": 0, "options": "Employee Onboarding Template",
"collapsible": 0, "show_days": 1,
"columns": 0, "show_seconds": 1
"fieldname": "project", },
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Project",
"length": 0,
"no_copy": 0,
"options": "Project",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "company",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 0, "label": "Company",
"bold": 0, "options": "Company",
"collapsible": 0, "show_days": 1,
"columns": 0, "show_seconds": 1
"fieldname": "table_for_activity", },
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "department",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 1, "in_list_view": 1,
"bold": 0, "label": "Department",
"collapsible": 0, "options": "Department",
"columns": 0, "show_days": 1,
"fieldname": "activities", "show_seconds": 1
"fieldtype": "Table", },
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Activities",
"length": 0,
"no_copy": 0,
"options": "Employee Boarding Activity",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "designation",
"allow_in_quick_entry": 0, "fieldtype": "Link",
"allow_on_submit": 0, "in_list_view": 1,
"bold": 0, "label": "Designation",
"collapsible": 0, "options": "Designation",
"columns": 0, "show_days": 1,
"fieldname": "amended_from", "show_seconds": 1
"fieldtype": "Link", },
"hidden": 0, {
"ignore_user_permissions": 0, "fieldname": "employee_grade",
"ignore_xss_filter": 0, "fieldtype": "Link",
"in_filter": 0, "label": "Employee Grade",
"in_global_search": 0, "options": "Employee Grade",
"in_list_view": 0, "show_days": 1,
"in_standard_filter": 0, "show_seconds": 1
"label": "Amended From", },
"length": 0, {
"no_copy": 1, "fieldname": "project",
"options": "Employee Onboarding", "fieldtype": "Link",
"permlevel": 0, "label": "Project",
"print_hide": 1, "options": "Project",
"print_hide_if_no_value": 0, "read_only": 1,
"read_only": 1, "show_days": 1,
"remember_last_selected_value": 0, "show_seconds": 1
"report_hide": 0, },
"reqd": 0, {
"search_index": 0, "fieldname": "table_for_activity",
"set_only_once": 0, "fieldtype": "Section Break",
"translatable": 0, "show_days": 1,
"unique": 0 "show_seconds": 1
},
{
"allow_on_submit": 1,
"fieldname": "activities",
"fieldtype": "Table",
"label": "Activities",
"options": "Employee Boarding Activity",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Employee Onboarding",
"print_hide": 1,
"read_only": 1,
"show_days": 1,
"show_seconds": 1
} }
], ],
"has_web_view": 0, "is_submittable": 1,
"hide_heading": 0, "links": [],
"hide_toolbar": 0, "modified": "2020-06-25 15:22:24.923835",
"idx": 0, "modified_by": "Administrator",
"image_view": 0, "module": "HR",
"in_create": 0, "name": "Employee Onboarding",
"is_submittable": 1, "owner": "Administrator",
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-08-01 16:15:55.968224",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Onboarding",
"name_case": "",
"owner": "Administrator",
"permissions": [ "permissions": [
{ {
"amend": 1, "amend": 1,
"cancel": 1, "cancel": 1,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"export": 1, "export": 1,
"if_owner": 0, "print": 1,
"import": 0, "read": 1,
"permlevel": 0, "report": 1,
"print": 1, "role": "System Manager",
"read": 1, "share": 1,
"report": 1, "submit": 1,
"role": "System Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 1,
"write": 1 "write": 1
} }
], ],
"quick_entry": 0, "sort_field": "modified",
"read_only": 0, "sort_order": "DESC",
"read_only_onload": 0, "title_field": "employee_name",
"show_name_in_global_search": 0, "track_changes": 1
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "employee_name",
"track_changes": 1,
"track_seen": 0,
"track_views": 0
} }

View File

@@ -13,6 +13,12 @@ class IncompleteTaskError(frappe.ValidationError): pass
class EmployeeOnboarding(EmployeeBoardingController): class EmployeeOnboarding(EmployeeBoardingController):
def validate(self): def validate(self):
super(EmployeeOnboarding, self).validate() super(EmployeeOnboarding, self).validate()
self.validate_duplicate_employee_onboarding()
def validate_duplicate_employee_onboarding(self):
emp_onboarding = frappe.db.exists("Employee Onboarding",{"job_applicant": self.job_applicant})
if emp_onboarding and emp_onboarding != self.name:
frappe.throw(_("Employee Onboarding: {0} is already for Job Applicant: {1}").format(frappe.bold(emp_onboarding), frappe.bold(self.job_applicant)))
def validate_employee_creation(self): def validate_employee_creation(self):
if self.docstatus != 1: if self.docstatus != 1:

View File

@@ -10,10 +10,14 @@ frappe.ui.form.on("Job Applicant", {
refresh: function(frm) { refresh: function(frm) {
if (!frm.doc.__islocal) { if (!frm.doc.__islocal) {
if (frm.doc.__onload && frm.doc.__onload.job_offer) { if (frm.doc.__onload && frm.doc.__onload.job_offer) {
$('[data-doctype="Employee Onboarding"]').find("button").show();
$('[data-doctype="Job Offer"]').find("button").hide();
frm.add_custom_button(__("Job Offer"), function() { frm.add_custom_button(__("Job Offer"), function() {
frappe.set_route("Form", "Job Offer", frm.doc.__onload.job_offer); frappe.set_route("Form", "Job Offer", frm.doc.__onload.job_offer);
}, __("View")); }, __("View"));
} else { } else {
$('[data-doctype="Employee Onboarding"]').find("button").hide();
$('[data-doctype="Job Offer"]').find("button").show();
frm.add_custom_button(__("Job Offer"), function() { frm.add_custom_button(__("Job Offer"), function() {
frappe.route_options = { frappe.route_options = {
"job_applicant": frm.doc.name, "job_applicant": frm.doc.name,

View File

@@ -15,6 +15,9 @@ class JobOffer(Document):
def validate(self): def validate(self):
self.validate_vacancies() self.validate_vacancies()
job_offer = frappe.db.exists("Job Offer",{"job_applicant": self.job_applicant})
if job_offer and job_offer != self.name:
frappe.throw(_("Job Offer: {0} is already for Job Applicant: {1}").format(frappe.bold(job_offer), frappe.bold(self.job_applicant)))
def validate_vacancies(self): def validate_vacancies(self):
staffing_plan = get_staffing_plan_detail(self.designation, self.company, self.offer_date) staffing_plan = get_staffing_plan_detail(self.designation, self.company, self.offer_date)