121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
import traceback
|
|
|
|
def get_or_create(model, domain, vals):
|
|
rec = env[model].search(domain, limit=1)
|
|
if not rec:
|
|
rec = env[model].create(vals)
|
|
print(f"Created {model}: {rec.id}")
|
|
else:
|
|
print(f"Found {model}: {rec.id}")
|
|
return rec
|
|
|
|
try:
|
|
# 1. Company
|
|
company = env["res.company"].search([], limit=1)
|
|
|
|
# 2. Campus
|
|
campus = get_or_create("education.campus", [("name", "=", "Test Campus")], {
|
|
"name": "Test Campus",
|
|
"company_id": company.id,
|
|
"code": "TC"
|
|
})
|
|
|
|
# 3. Department
|
|
dept = get_or_create("education.department", [("name", "=", "Test Dept")], {
|
|
"name": "Test Dept",
|
|
"company_id": company.id,
|
|
"campus_id": campus.id,
|
|
"code": "TD"
|
|
})
|
|
|
|
# 4. Academic Level
|
|
level = get_or_create("education.academic.level", [("name", "=", "Test Level")], {
|
|
"name": "Test Level",
|
|
"company_id": company.id,
|
|
"code": "TL"
|
|
})
|
|
|
|
# 5. Program
|
|
program = get_or_create("education.program", [("name", "=", "Test Program")], {
|
|
"name": "Test Program",
|
|
"department_id": dept.id,
|
|
"level_id": level.id,
|
|
"code": "TP"
|
|
})
|
|
|
|
# 6. Academic Year
|
|
year = get_or_create("education.academic.year", [("name", "=", "Test Year")], {
|
|
"name": "Test Year",
|
|
"company_id": company.id,
|
|
"start_date": "2026-01-01",
|
|
"end_date": "2026-12-31"
|
|
})
|
|
|
|
# 7. Academic Term
|
|
term = get_or_create("education.academic.term", [("name", "=", "Test Term")], {
|
|
"name": "Test Term",
|
|
"academic_year_id": year.id,
|
|
"start_date": "2026-01-01",
|
|
"end_date": "2026-06-30"
|
|
})
|
|
|
|
# 8. Batch
|
|
batch = get_or_create("education.batch", [("name", "=", "Test Batch")], {
|
|
"name": "Test Batch",
|
|
"program_id": program.id,
|
|
"academic_year_id": year.id,
|
|
"start_date": "2026-01-01",
|
|
"end_date": "2026-12-31"
|
|
})
|
|
|
|
# 9. Semester
|
|
semester = get_or_create("education.semester", [("name", "=", "Test Semester")], {
|
|
"name": "Test Semester",
|
|
"program_id": program.id,
|
|
"academic_year_id": year.id,
|
|
"sequence": 1
|
|
})
|
|
|
|
# res.users (demo.student)
|
|
user = env["res.users"].search([("login", "=", "demo.student")], limit=1)
|
|
|
|
# 10. Student
|
|
student = env["education.student"].search([("portal_user_id", "=", user.id)], limit=1)
|
|
if not student:
|
|
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,
|
|
"company_id": company.id,
|
|
"campus_id": campus.id,
|
|
"department_id": dept.id,
|
|
"level_id": level.id,
|
|
"program_id": program.id,
|
|
"academic_year_id": year.id,
|
|
"academic_term_id": term.id,
|
|
"batch_id": batch.id,
|
|
"semester_id": semester.id,
|
|
"current_semester_id": semester.id,
|
|
"date_of_birth": "2000-01-01",
|
|
"gender": "other",
|
|
"admission_number": "ADM-9999",
|
|
"student_id": "STU-9999",
|
|
"status": "active"
|
|
})
|
|
print(f"Created Student: {student.id}")
|
|
else:
|
|
print(f"Found Student: {student.id}")
|
|
|
|
env.cr.commit()
|
|
with open('/mnt/extra-addons/success.log', 'w') as f:
|
|
f.write(f"ALL DONE. Student ID: {student.id}\n")
|
|
print("SUCCESS")
|
|
|
|
except Exception as e:
|
|
print("FAILED")
|
|
traceback.print_exc()
|
|
with open('/mnt/extra-addons/error.log', 'w') as f:
|
|
f.write(traceback.format_exc())
|