Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 1 | import frappe |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 2 | from frappe.utils import getdate |
| 3 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 4 | |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 5 | @frappe.whitelist() |
| 6 | def create_employee_records(): |
Rucha Mahabal | 525d4d4 | 2021-07-15 19:32:15 +0530 | [diff] [blame] | 7 | create_company() |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 8 | create_missing_designation() |
| 9 | |
Rucha Mahabal | 9e08229 | 2021-09-30 18:32:10 +0530 | [diff] [blame] | 10 | frappe.db.sql("DELETE FROM tabEmployee WHERE company='Test Org Chart'") |
| 11 | |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 12 | emp1 = create_employee('Test Employee 1', 'CEO') |
| 13 | emp2 = create_employee('Test Employee 2', 'CTO') |
| 14 | emp3 = create_employee('Test Employee 3', 'Head of Marketing and Sales', emp1) |
| 15 | emp4 = create_employee('Test Employee 4', 'Project Manager', emp2) |
Rucha Mahabal | a1d379d | 2021-07-15 19:19:09 +0530 | [diff] [blame] | 16 | emp5 = create_employee('Test Employee 5', 'Engineer', emp2) |
| 17 | emp6 = create_employee('Test Employee 6', 'Analyst', emp3) |
| 18 | emp7 = create_employee('Test Employee 7', 'Software Developer', emp4) |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 19 | |
Rucha Mahabal | a1d379d | 2021-07-15 19:19:09 +0530 | [diff] [blame] | 20 | employees = [emp1, emp2, emp3, emp4, emp5, emp6, emp7] |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 21 | return employees |
| 22 | |
Rucha Mahabal | 982a097 | 2021-07-19 22:19:28 +0530 | [diff] [blame] | 23 | @frappe.whitelist() |
| 24 | def get_employee_records(): |
| 25 | return frappe.db.get_list('Employee', filters={ |
| 26 | 'company': 'Test Org Chart' |
| 27 | }, pluck='name', order_by='name') |
| 28 | |
Rucha Mahabal | 3cc85e1 | 2021-07-14 23:50:54 +0530 | [diff] [blame] | 29 | def create_company(): |
| 30 | company = frappe.db.exists('Company', 'Test Org Chart') |
| 31 | if not company: |
| 32 | company = frappe.get_doc({ |
| 33 | 'doctype': 'Company', |
| 34 | 'company_name': 'Test Org Chart', |
| 35 | 'country': 'India', |
| 36 | 'default_currency': 'INR' |
| 37 | }).insert().name |
| 38 | |
| 39 | return company |
| 40 | |
| 41 | def create_employee(first_name, designation, reports_to=None): |
| 42 | employee = frappe.db.exists('Employee', {'first_name': first_name, 'designation': designation}) |
| 43 | if not employee: |
| 44 | employee = frappe.get_doc({ |
| 45 | 'doctype': 'Employee', |
| 46 | 'first_name': first_name, |
| 47 | 'company': 'Test Org Chart', |
| 48 | 'gender': 'Female', |
| 49 | 'date_of_birth': getdate('08-12-1998'), |
| 50 | 'date_of_joining': getdate('01-01-2021'), |
| 51 | 'designation': designation, |
| 52 | 'reports_to': reports_to |
| 53 | }).insert().name |
| 54 | |
| 55 | return employee |
| 56 | |
| 57 | def create_missing_designation(): |
| 58 | if not frappe.db.exists('Designation', 'CTO'): |
| 59 | frappe.get_doc({ |
| 60 | 'doctype': 'Designation', |
| 61 | 'designation_name': 'CTO' |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 62 | }).insert() |