From ab0ef609188c232ae16e16b553ecac3a7e1bffcc Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 26 May 2022 11:32:46 +0530 Subject: [PATCH] test: Job Opening against a Staffing Plan --- .../doctype/job_opening/test_job_opening.py | 75 ++++++++++++++++++- .../staffing_plan/test_staffing_plan.py | 11 ++- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/erpnext/hr/doctype/job_opening/test_job_opening.py b/erpnext/hr/doctype/job_opening/test_job_opening.py index a72a6eb338..e991054f62 100644 --- a/erpnext/hr/doctype/job_opening/test_job_opening.py +++ b/erpnext/hr/doctype/job_opening/test_job_opening.py @@ -3,8 +3,77 @@ import unittest -# test_records = frappe.get_test_records('Job Opening') +import frappe +from frappe.tests.utils import FrappeTestCase +from frappe.utils import add_days, getdate + +from erpnext.hr.doctype.employee.test_employee import make_employee +from erpnext.hr.doctype.staffing_plan.test_staffing_plan import make_company -class TestJobOpening(unittest.TestCase): - pass +class TestJobOpening(FrappeTestCase): + def setUp(self): + frappe.db.delete("Staffing Plan") + frappe.db.delete("Staffing Plan Detail") + frappe.db.delete("Job Opening") + + make_company("_Test Opening Company", "_TOC") + frappe.db.delete("Employee", {"company": "_Test Opening Company"}) + + def test_vacancies_fulfilled(self): + make_employee( + "test_job_opening@example.com", company="_Test Opening Company", designation="Designer" + ) + + staffing_plan = frappe.get_doc( + { + "doctype": "Staffing Plan", + "company": "_Test Opening Company", + "name": "Test", + "from_date": getdate(), + "to_date": add_days(getdate(), 10), + } + ) + + staffing_plan.append( + "staffing_details", + {"designation": "Designer", "vacancies": 1, "estimated_cost_per_position": 50000}, + ) + staffing_plan.insert() + staffing_plan.submit() + + self.assertEqual(staffing_plan.staffing_details[0].number_of_positions, 2) + + # allows creating 1 job opening as per vacancy + opening_1 = get_job_opening() + opening_1.insert() + + # vacancies as per staffing plan already fulfilled via job opening and existing employee count + opening_2 = get_job_opening(job_title="Designer New") + self.assertRaises(frappe.ValidationError, opening_2.insert) + + # allows updating existing job opening + opening_1.status = "Closed" + opening_1.save() + + +def get_job_opening(**args): + args = frappe._dict(args) + + opening = frappe.db.exists("Job Opening", {"job_title": args.job_title or "Designer"}) + if opening: + return frappe.get_doc("Job Opening", opening) + + opening = frappe.get_doc( + { + "doctype": "Job Opening", + "job_title": "Designer", + "designation": "Designer", + "company": "_Test Opening Company", + "status": "Open", + } + ) + + opening.update(args) + + return opening diff --git a/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py b/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py index a3adbbd56a..ac69c21979 100644 --- a/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py +++ b/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py @@ -85,13 +85,16 @@ def _set_up(): make_company() -def make_company(): - if frappe.db.exists("Company", "_Test Company 10"): +def make_company(name=None, abbr=None): + if not name: + name = "_Test Company 10" + + if frappe.db.exists("Company", name): return company = frappe.new_doc("Company") - company.company_name = "_Test Company 10" - company.abbr = "_TC10" + company.company_name = name + company.abbr = abbr or "_TC10" company.parent_company = "_Test Company 3" company.default_currency = "INR" company.country = "Pakistan"