2021-07-14 18:20:54 +00:00
|
|
|
import frappe
|
|
|
|
from frappe.utils import getdate
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2021-07-14 18:20:54 +00:00
|
|
|
@frappe.whitelist()
|
|
|
|
def create_employee_records():
|
2021-07-15 14:02:15 +00:00
|
|
|
create_company()
|
2021-07-14 18:20:54 +00:00
|
|
|
create_missing_designation()
|
|
|
|
|
2021-09-30 13:02:10 +00:00
|
|
|
frappe.db.sql("DELETE FROM tabEmployee WHERE company='Test Org Chart'")
|
|
|
|
|
2021-07-14 18:20:54 +00:00
|
|
|
emp1 = create_employee("Test Employee 1", "CEO")
|
|
|
|
emp2 = create_employee("Test Employee 2", "CTO")
|
|
|
|
emp3 = create_employee("Test Employee 3", "Head of Marketing and Sales", emp1)
|
|
|
|
emp4 = create_employee("Test Employee 4", "Project Manager", emp2)
|
2021-07-15 13:49:09 +00:00
|
|
|
emp5 = create_employee("Test Employee 5", "Engineer", emp2)
|
|
|
|
emp6 = create_employee("Test Employee 6", "Analyst", emp3)
|
|
|
|
emp7 = create_employee("Test Employee 7", "Software Developer", emp4)
|
2021-07-14 18:20:54 +00:00
|
|
|
|
2021-07-15 13:49:09 +00:00
|
|
|
employees = [emp1, emp2, emp3, emp4, emp5, emp6, emp7]
|
2021-07-14 18:20:54 +00:00
|
|
|
return employees
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2021-07-19 16:49:28 +00:00
|
|
|
@frappe.whitelist()
|
|
|
|
def get_employee_records():
|
|
|
|
return frappe.db.get_list(
|
|
|
|
"Employee", filters={"company": "Test Org Chart"}, pluck="name", order_by="name"
|
|
|
|
)
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2021-07-19 16:49:28 +00:00
|
|
|
|
2021-07-14 18:20:54 +00:00
|
|
|
def create_company():
|
|
|
|
company = frappe.db.exists("Company", "Test Org Chart")
|
|
|
|
if not company:
|
|
|
|
company = (
|
|
|
|
frappe.get_doc(
|
|
|
|
{
|
|
|
|
"doctype": "Company",
|
|
|
|
"company_name": "Test Org Chart",
|
|
|
|
"country": "India",
|
|
|
|
"default_currency": "INR",
|
|
|
|
}
|
2022-03-28 13:22:46 +00:00
|
|
|
)
|
2021-07-14 18:20:54 +00:00
|
|
|
.insert()
|
|
|
|
.name
|
2022-03-28 13:22:46 +00:00
|
|
|
)
|
2021-07-14 18:20:54 +00:00
|
|
|
|
|
|
|
return company
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2021-07-14 18:20:54 +00:00
|
|
|
def create_employee(first_name, designation, reports_to=None):
|
|
|
|
employee = frappe.db.exists("Employee", {"first_name": first_name, "designation": designation})
|
|
|
|
if not employee:
|
|
|
|
employee = (
|
|
|
|
frappe.get_doc(
|
|
|
|
{
|
|
|
|
"doctype": "Employee",
|
|
|
|
"first_name": first_name,
|
|
|
|
"company": "Test Org Chart",
|
|
|
|
"gender": "Female",
|
|
|
|
"date_of_birth": getdate("08-12-1998"),
|
|
|
|
"date_of_joining": getdate("01-01-2021"),
|
|
|
|
"designation": designation,
|
|
|
|
"reports_to": reports_to,
|
|
|
|
}
|
2022-03-28 13:22:46 +00:00
|
|
|
)
|
2021-07-14 18:20:54 +00:00
|
|
|
.insert()
|
|
|
|
.name
|
2022-03-28 13:22:46 +00:00
|
|
|
)
|
2021-07-14 18:20:54 +00:00
|
|
|
|
|
|
|
return employee
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2021-07-14 18:20:54 +00:00
|
|
|
def create_missing_designation():
|
|
|
|
if not frappe.db.exists("Designation", "CTO"):
|
|
|
|
frappe.get_doc({"doctype": "Designation", "designation_name": "CTO"}).insert()
|