Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
Aditya Hase | f3c22f3 | 2019-01-22 18:22:20 +0530 | [diff] [blame] | 3 | from __future__ import unicode_literals |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 4 | |
| 5 | import frappe, json |
| 6 | from frappe.utils.make_random import get_random |
| 7 | from datetime import datetime |
| 8 | from erpnext.demo.setup.setup_data import import_json |
| 9 | import random |
| 10 | |
| 11 | def setup_data(): |
| 12 | frappe.flags.mute_emails = True |
| 13 | make_masters() |
| 14 | setup_item() |
| 15 | make_student_applicants() |
| 16 | make_student_group() |
| 17 | make_fees_category() |
| 18 | make_fees_structure() |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 19 | make_assessment_groups() |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 20 | frappe.db.commit() |
| 21 | frappe.clear_cache() |
| 22 | |
| 23 | def make_masters(): |
| 24 | import_json("Room") |
| 25 | import_json("Department") |
| 26 | import_json("Instructor") |
| 27 | import_json("Course") |
| 28 | import_json("Program") |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 29 | import_json("Student Batch Name") |
| 30 | import_json("Assessment Criteria") |
| 31 | import_json("Grading Scale") |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 32 | frappe.db.commit() |
| 33 | |
| 34 | def setup_item(): |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 35 | items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item_education.json')).read()) |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 36 | for i in items: |
| 37 | item = frappe.new_doc('Item') |
| 38 | item.update(i) |
| 39 | item.min_order_qty = random.randint(10, 30) |
Manas Solanki | 087a225 | 2018-05-04 16:02:38 +0530 | [diff] [blame] | 40 | item.item_defaults[0].default_warehouse = frappe.get_all('Warehouse', |
| 41 | filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1)[0].name |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 42 | item.insert() |
| 43 | |
| 44 | def make_student_applicants(): |
| 45 | blood_group = ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"] |
| 46 | male_names = [] |
| 47 | female_names = [] |
| 48 | |
| 49 | file_path = get_json_path("Random Student Data") |
| 50 | with open(file_path, "r") as open_file: |
| 51 | random_student_data = json.loads(open_file.read()) |
| 52 | count = 1 |
| 53 | |
| 54 | for d in random_student_data: |
| 55 | if d.get('gender') == "Male": |
| 56 | male_names.append(d.get('first_name').title()) |
| 57 | |
| 58 | if d.get('gender') == "Female": |
| 59 | female_names.append(d.get('first_name').title()) |
| 60 | |
| 61 | for idx, d in enumerate(random_student_data): |
| 62 | student_applicant = frappe.new_doc("Student Applicant") |
| 63 | student_applicant.first_name = d.get('first_name').title() |
| 64 | student_applicant.last_name = d.get('last_name').title() |
| 65 | student_applicant.image = d.get('image') |
| 66 | student_applicant.gender = d.get('gender') |
| 67 | student_applicant.program = get_random("Program") |
| 68 | student_applicant.blood_group = random.choice(blood_group) |
| 69 | year = random.randint(1990, 1998) |
| 70 | month = random.randint(1, 12) |
| 71 | day = random.randint(1, 28) |
| 72 | student_applicant.date_of_birth = datetime(year, month, day) |
| 73 | student_applicant.mother_name = random.choice(female_names) + " " + d.get('last_name').title() |
| 74 | student_applicant.father_name = random.choice(male_names) + " " + d.get('last_name').title() |
| 75 | if student_applicant.gender == "Male": |
| 76 | student_applicant.middle_name = random.choice(male_names) |
| 77 | else: |
| 78 | student_applicant.middle_name = random.choice(female_names) |
| 79 | student_applicant.student_email_id = d.get('first_name') + "_" + \ |
| 80 | student_applicant.middle_name + "_" + d.get('last_name') + "@example.com" |
| 81 | if count <5: |
| 82 | student_applicant.insert() |
| 83 | frappe.db.commit() |
| 84 | else: |
| 85 | student_applicant.submit() |
| 86 | frappe.db.commit() |
| 87 | count+=1 |
| 88 | |
| 89 | def make_student_group(): |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 90 | for term in frappe.db.get_list("Academic Term"): |
| 91 | for program in frappe.db.get_list("Program"): |
| 92 | sg_tool = frappe.new_doc("Student Group Creation Tool") |
| 93 | sg_tool.academic_year = "2017-18" |
| 94 | sg_tool.academic_term = term.name |
| 95 | sg_tool.program = program.name |
| 96 | for d in sg_tool.get_courses(): |
| 97 | d = frappe._dict(d) |
| 98 | student_group = frappe.new_doc("Student Group") |
| 99 | student_group.student_group_name = d.student_group_name |
| 100 | student_group.group_based_on = d.group_based_on |
| 101 | student_group.program = program.name |
| 102 | student_group.course = d.course |
| 103 | student_group.batch = d.batch |
| 104 | student_group.academic_term = term.name |
| 105 | student_group.academic_year = "2017-18" |
| 106 | student_group.save() |
| 107 | frappe.db.commit() |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 108 | |
| 109 | def make_fees_category(): |
| 110 | fee_type = ["Tuition Fee", "Hostel Fee", "Logistics Fee", |
| 111 | "Medical Fee", "Mess Fee", "Security Deposit"] |
| 112 | |
| 113 | fee_desc = {"Tuition Fee" : "Curricular activities which includes books, notebooks and faculty charges" , |
| 114 | "Hostel Fee" : "Stay of students in institute premises", |
| 115 | "Logistics Fee" : "Lodging boarding of the students" , |
| 116 | "Medical Fee" : "Medical welfare of the students", |
| 117 | "Mess Fee" : "Food and beverages for your ward", |
| 118 | "Security Deposit" : "In case your child is found to have damaged institutes property" |
| 119 | } |
| 120 | |
| 121 | for i in fee_type: |
| 122 | fee_category = frappe.new_doc("Fee Category") |
| 123 | fee_category.category_name = i |
| 124 | fee_category.description = fee_desc[i] |
| 125 | fee_category.insert() |
| 126 | frappe.db.commit() |
| 127 | |
| 128 | def make_fees_structure(): |
| 129 | for d in frappe.db.get_list("Program"): |
| 130 | program = frappe.get_doc("Program", d.name) |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 131 | for academic_term in ["2017-18 (Semester 1)", "2017-18 (Semester 2)", "2017-18 (Semester 3)"]: |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 132 | fee_structure = frappe.new_doc("Fee Structure") |
| 133 | fee_structure.program = d.name |
| 134 | fee_structure.academic_term = random.choice(frappe.db.get_list("Academic Term")).name |
| 135 | for j in range(1,4): |
| 136 | temp = {"fees_category": random.choice(frappe.db.get_list("Fee Category")).name , "amount" : random.randint(500,1000)} |
| 137 | fee_structure.append("components", temp) |
| 138 | fee_structure.insert() |
| 139 | program.append("fees", {"academic_term": academic_term, "fee_structure": fee_structure.name, "amount": fee_structure.total_amount}) |
| 140 | program.save() |
| 141 | frappe.db.commit() |
| 142 | |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 143 | def make_assessment_groups(): |
| 144 | for year in frappe.db.get_list("Academic Year"): |
| 145 | ag = frappe.new_doc('Assessment Group') |
| 146 | ag.assessment_group_name = year.name |
| 147 | ag.parent_assessment_group = "All Assessment Groups" |
| 148 | ag.is_group = 1 |
| 149 | ag.insert() |
| 150 | for term in frappe.db.get_list("Academic Term", filters = {"academic_year": year.name}): |
| 151 | ag1 = frappe.new_doc('Assessment Group') |
| 152 | ag1.assessment_group_name = term.name |
| 153 | ag1.parent_assessment_group = ag.name |
| 154 | ag1.is_group = 1 |
| 155 | ag1.insert() |
| 156 | for assessment_group in ['Term I', 'Term II']: |
| 157 | ag2 = frappe.new_doc('Assessment Group') |
| 158 | ag2.assessment_group_name = ag1.name + " " + assessment_group |
| 159 | ag2.parent_assessment_group = ag1.name |
| 160 | ag2.insert() |
| 161 | frappe.db.commit() |
| 162 | |
| 163 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 164 | def get_json_path(doctype): |
| 165 | return frappe.get_app_path('erpnext', 'demo', 'data', frappe.scrub(doctype) + '.json') |
Aditya Hase | f3c22f3 | 2019-01-22 18:22:20 +0530 | [diff] [blame] | 166 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 167 | def weighted_choice(weights): |
| 168 | totals = [] |
| 169 | running_total = 0 |
| 170 | |
| 171 | for w in weights: |
| 172 | running_total += w |
| 173 | totals.append(running_total) |
| 174 | |
| 175 | rnd = random.random() * running_total |
| 176 | for i, total in enumerate(totals): |
| 177 | if rnd < total: |
| 178 | return i |