40 lines
1.7 KiB
Python
40 lines
1.7 KiB
Python
import traceback
|
|
with open('/tmp/student_create.log', 'w') as f:
|
|
try:
|
|
campus = env["education.campus"].search([], limit=1)
|
|
if not campus:
|
|
campus = env["education.campus"].create({"name": "Test Campus"})
|
|
dept = env["education.department"].search([], limit=1)
|
|
if not dept:
|
|
dept = env["education.department"].create({"name": "Test Dept"})
|
|
prog = env["education.program"].search([], limit=1)
|
|
if not prog:
|
|
prog = env["education.program"].create({"name": "Test Program"})
|
|
year = env["education.academic.year"].search([], limit=1)
|
|
if not year:
|
|
year = env["education.academic.year"].create({"name": "2026"})
|
|
user = env["res.users"].search([("login", "=", "demo.student")], limit=1)
|
|
|
|
f.write(f"Campus: {campus.id}, Dept: {dept.id}, Prog: {prog.id}, Year: {year.id}, User: {user.id}\n")
|
|
|
|
student = env["education.student"].create({
|
|
"full_name": "Demo Student",
|
|
"first_name": "Demo",
|
|
"last_name": "Student",
|
|
"email": "demo.student@example.com",
|
|
"portal_user_id": user.id if user else False,
|
|
"campus_id": campus.id,
|
|
"department_id": dept.id,
|
|
"program_id": prog.id,
|
|
"academic_year_id": year.id,
|
|
"date_of_birth": "2000-01-01",
|
|
"gender": "other",
|
|
"admission_number": "ADM-9999",
|
|
"student_id": "STU-9999"
|
|
})
|
|
env.cr.commit()
|
|
f.write(f"SUCCESS, STUDENT ID: {student.id}\n")
|
|
except Exception as e:
|
|
f.write("ERROR DURING CREATE:\n")
|
|
f.write(traceback.format_exc())
|