mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
* fix: autoname generated for Job Applicant is too long (#29260)
* fix: autoname generated for Job Applicant is too long
- autoname based on email and append number if exists instead of concatenating name, email, title
- add more search fields for context during selection
* test: Job applicant naming and fix related tests
(cherry picked from commit 5cda4ea39f)
# Conflicts:
# erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py
* fix: conflicts
Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com>
This commit is contained in:
@@ -17,7 +17,10 @@ class TestEmployeeOnboarding(unittest.TestCase):
|
|||||||
def test_employee_onboarding_incomplete_task(self):
|
def test_employee_onboarding_incomplete_task(self):
|
||||||
if frappe.db.exists('Employee Onboarding', {'employee_name': 'Test Researcher'}):
|
if frappe.db.exists('Employee Onboarding', {'employee_name': 'Test Researcher'}):
|
||||||
frappe.delete_doc('Employee Onboarding', {'employee_name': 'Test Researcher'})
|
frappe.delete_doc('Employee Onboarding', {'employee_name': 'Test Researcher'})
|
||||||
_set_up()
|
frappe.db.sql("delete from `tabEmployee Onboarding`")
|
||||||
|
project = "Employee Onboarding : test@researcher.com"
|
||||||
|
frappe.db.sql("delete from tabProject where name=%s", project)
|
||||||
|
frappe.db.sql("delete from tabTask where project=%s", project)
|
||||||
applicant = get_job_applicant()
|
applicant = get_job_applicant()
|
||||||
|
|
||||||
job_offer = create_job_offer(job_applicant=applicant.name)
|
job_offer = create_job_offer(job_applicant=applicant.name)
|
||||||
@@ -42,7 +45,7 @@ class TestEmployeeOnboarding(unittest.TestCase):
|
|||||||
onboarding.submit()
|
onboarding.submit()
|
||||||
|
|
||||||
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')
|
self.assertEqual(project_name, 'Employee Onboarding : test@researcher.com')
|
||||||
|
|
||||||
# don't allow making employee if onboarding is not complete
|
# don't allow making employee if onboarding is not complete
|
||||||
self.assertRaises(IncompleteTaskError, make_employee, onboarding.name)
|
self.assertRaises(IncompleteTaskError, make_employee, onboarding.name)
|
||||||
@@ -65,8 +68,8 @@ class TestEmployeeOnboarding(unittest.TestCase):
|
|||||||
self.assertEqual(employee.employee_name, 'Test Researcher')
|
self.assertEqual(employee.employee_name, 'Test Researcher')
|
||||||
|
|
||||||
def get_job_applicant():
|
def get_job_applicant():
|
||||||
if frappe.db.exists('Job Applicant', 'Test Researcher - test@researcher.com'):
|
if frappe.db.exists('Job Applicant', 'test@researcher.com'):
|
||||||
return frappe.get_doc('Job Applicant', 'Test Researcher - test@researcher.com')
|
return frappe.get_doc('Job Applicant', 'test@researcher.com')
|
||||||
applicant = frappe.new_doc('Job Applicant')
|
applicant = frappe.new_doc('Job Applicant')
|
||||||
applicant.applicant_name = 'Test Researcher'
|
applicant.applicant_name = 'Test Researcher'
|
||||||
applicant.email_id = 'test@researcher.com'
|
applicant.email_id = 'test@researcher.com'
|
||||||
|
|||||||
@@ -192,10 +192,11 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-09-29 23:06:10.904260",
|
"modified": "2022-01-12 16:28:53.196881",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Job Applicant",
|
"name": "Job Applicant",
|
||||||
|
"naming_rule": "Expression (old style)",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -210,10 +211,11 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"search_fields": "applicant_name",
|
"search_fields": "applicant_name, email_id, job_title, phone_number",
|
||||||
"sender_field": "email_id",
|
"sender_field": "email_id",
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "ASC",
|
"sort_order": "ASC",
|
||||||
|
"states": [],
|
||||||
"subject_field": "notes",
|
"subject_field": "notes",
|
||||||
"title_field": "applicant_name"
|
"title_field": "applicant_name"
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.model.naming import append_number_if_name_exists
|
||||||
from frappe.utils import validate_email_address
|
from frappe.utils import validate_email_address
|
||||||
|
|
||||||
from erpnext.hr.doctype.interview.interview import get_interviewers
|
from erpnext.hr.doctype.interview.interview import get_interviewers
|
||||||
@@ -21,10 +22,11 @@ class JobApplicant(Document):
|
|||||||
self.get("__onload").job_offer = job_offer[0].name
|
self.get("__onload").job_offer = job_offer[0].name
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
keys = filter(None, (self.applicant_name, self.email_id, self.job_title))
|
self.name = self.email_id
|
||||||
if not keys:
|
|
||||||
frappe.throw(_("Name or Email is mandatory"), frappe.NameError)
|
# applicant can apply more than once for a different job title or reapply
|
||||||
self.name = " - ".join(keys)
|
if frappe.db.exists("Job Applicant", self.name):
|
||||||
|
self.name = append_number_if_name_exists("Job Applicant", self.name)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if self.email_id:
|
if self.email_id:
|
||||||
|
|||||||
@@ -9,7 +9,26 @@ from erpnext.hr.doctype.designation.test_designation import create_designation
|
|||||||
|
|
||||||
|
|
||||||
class TestJobApplicant(unittest.TestCase):
|
class TestJobApplicant(unittest.TestCase):
|
||||||
pass
|
def test_job_applicant_naming(self):
|
||||||
|
applicant = frappe.get_doc({
|
||||||
|
"doctype": "Job Applicant",
|
||||||
|
"status": "Open",
|
||||||
|
"applicant_name": "_Test Applicant",
|
||||||
|
"email_id": "job_applicant_naming@example.com"
|
||||||
|
}).insert()
|
||||||
|
self.assertEqual(applicant.name, 'job_applicant_naming@example.com')
|
||||||
|
|
||||||
|
applicant = frappe.get_doc({
|
||||||
|
"doctype": "Job Applicant",
|
||||||
|
"status": "Open",
|
||||||
|
"applicant_name": "_Test Applicant",
|
||||||
|
"email_id": "job_applicant_naming@example.com"
|
||||||
|
}).insert()
|
||||||
|
self.assertEqual(applicant.name, 'job_applicant_naming@example.com-1')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
|
|
||||||
def create_job_applicant(**args):
|
def create_job_applicant(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
Reference in New Issue
Block a user