This repository has been archived by the owner on Sep 13, 2021. It is now read-only.
/
make_demo.py
115 lines (99 loc) · 3.47 KB
/
make_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe, os, json
from frappe.core.page.data_import_tool.data_import_tool import import_doc
from schools.simulate import simulate
from frappe.utils.make_random import get_random
from datetime import datetime
import time, random
def make():
frappe.flags.mute_emails = True
setup()
frappe.set_user("Administrator")
def setup():
print "Completing Setup..."
complete_setup()
print "Making Masters..."
make_masters()
make_student_applicants()
make_student_group()
print "Starting Simulation..."
time.sleep(5)
simulate()
def complete_setup():
from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
setup_complete({
"first_name": "Demo",
"last_name": "User",
"email": "demo@erpnext.com",
"company_tagline": "Inspiring Minds",
"password": "demo",
"fy_start_date": "2015-01-01",
"fy_end_date": "2015-12-31",
"industry": "Education",
"company_name": "Whitemore College",
"chart_of_accounts": "Standard",
"company_abbr": "WC",
"country": "United States",
"currency": "USD",
"timezone": "America/New_York",
"bank_name": "Citibank",
"language": "english"
})
# home page should always be "start"
website_settings = frappe.get_doc("Website Settings", "Website Settings")
website_settings.home_page = "start"
website_settings.save()
frappe.clear_cache()
def make_masters():
import_data("Room")
import_data("Department")
import_data("Instructor")
import_data("Course")
import_data("Program")
def make_student_applicants():
blood_group = ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"]
male_names = []
female_names = []
file_path = get_json_path("Random Student Data")
with open(file_path, "r") as open_file:
random_student_data = json.loads(open_file.read())
count = 1
for d in random_student_data:
if d.get('gender') == "Male":
male_names.append(d.get('first_name').title())
if d.get('gender') == "Female":
female_names.append(d.get('first_name').title())
for d in random_student_data:
student_applicant = frappe.new_doc("Student Applicant")
student_applicant.first_name = d.get('first_name').title()
student_applicant.last_name = d.get('last_name').title()
student_applicant.image = d.get('image')
student_applicant.gender = d.get('gender')
student_applicant.program = get_random("Program")
student_applicant.blood_group = random.choice(blood_group)
year = random.randint(1990, 1998)
month = random.randint(1, 12)
day = random.randint(1, 28)
student_applicant.date_of_birth = datetime(year, month, day)
student_applicant.mother_name = random.choice(female_names) + " " + d.get('last_name').title()
student_applicant.father_name = random.choice(male_names) + " " + d.get('last_name').title()
if count <5:
student_applicant.save()
else:
student_applicant.submit()
count+=1
def make_student_group():
for d in frappe.db.get_list("Academic Term"):
sg_tool = frappe.new_doc("Student Group Creation Tool")
sg_tool.academic_year = "2016-17"
sg_tool.academic_term = d.name
sg_tool.courses = sg_tool.get_courses()
sg_tool.create_student_groups()
def import_data(dt, submit=False, overwrite=False):
if not isinstance(dt, (tuple, list)):
dt = [dt]
for doctype in dt:
import_doc(get_json_path(doctype), submit=submit, overwrite=overwrite)
def get_json_path(doctype):
return os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".json")