Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 1 | # Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors |
| 2 | # For license information, please see license.txt |
| 3 | |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 4 | |
| 5 | import frappe |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 6 | |
| 7 | |
| 8 | def setup_education(): |
Shivam Mishra | 08425d4 | 2019-05-29 15:42:57 +0530 | [diff] [blame] | 9 | disable_desk_access_for_student_role() |
| 10 | if frappe.db.exists("Academic Year", "2015-16"): |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 11 | # already setup |
| 12 | return |
| 13 | create_academic_sessions() |
| 14 | |
Ankush Menat | 457d616 | 2022-01-21 21:40:47 +0530 | [diff] [blame] | 15 | |
| 16 | def insert_record(records): |
| 17 | for r in records: |
| 18 | doc = frappe.new_doc(r.get("doctype")) |
| 19 | doc.update(r) |
| 20 | try: |
| 21 | doc.insert(ignore_permissions=True) |
| 22 | except frappe.DuplicateEntryError as e: |
| 23 | # pass DuplicateEntryError and continue |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 24 | if e.args and e.args[0] == doc.doctype and e.args[1] == doc.name: |
Ankush Menat | 457d616 | 2022-01-21 21:40:47 +0530 | [diff] [blame] | 25 | # make sure DuplicateEntryError is for the exact same doc and not a related doc |
| 26 | pass |
| 27 | else: |
| 28 | raise |
| 29 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 30 | |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 31 | def create_academic_sessions(): |
| 32 | data = [ |
| 33 | {"doctype": "Academic Year", "academic_year_name": "2015-16"}, |
| 34 | {"doctype": "Academic Year", "academic_year_name": "2016-17"}, |
| 35 | {"doctype": "Academic Year", "academic_year_name": "2017-18"}, |
| 36 | {"doctype": "Academic Year", "academic_year_name": "2018-19"}, |
| 37 | {"doctype": "Academic Term", "academic_year": "2016-17", "term_name": "Semester 1"}, |
| 38 | {"doctype": "Academic Term", "academic_year": "2016-17", "term_name": "Semester 2"}, |
| 39 | {"doctype": "Academic Term", "academic_year": "2017-18", "term_name": "Semester 1"}, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 40 | {"doctype": "Academic Term", "academic_year": "2017-18", "term_name": "Semester 2"}, |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 41 | ] |
| 42 | insert_record(data) |
Shivam Mishra | 08425d4 | 2019-05-29 15:42:57 +0530 | [diff] [blame] | 43 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 44 | |
Shivam Mishra | 08425d4 | 2019-05-29 15:42:57 +0530 | [diff] [blame] | 45 | def disable_desk_access_for_student_role(): |
| 46 | try: |
| 47 | student_role = frappe.get_doc("Role", "Student") |
| 48 | except frappe.DoesNotExistError: |
| 49 | create_student_role() |
| 50 | return |
| 51 | |
| 52 | student_role.desk_access = 0 |
| 53 | student_role.save() |
| 54 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 55 | |
Shivam Mishra | 08425d4 | 2019-05-29 15:42:57 +0530 | [diff] [blame] | 56 | def create_student_role(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 57 | student_role = frappe.get_doc( |
| 58 | {"doctype": "Role", "role_name": "Student", "desk_access": 0, "restrict_to_domain": "Education"} |
| 59 | ) |
Shivam Mishra | 9cad943 | 2019-06-05 17:52:21 +0530 | [diff] [blame] | 60 | student_role.insert() |