121 lines
4.5 KiB
Python

from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
class TestEducationStudent(TransactionCase):
def setUp(self):
super().setUp()
self.company = self.env.company
self.campus = self.env['education.campus'].create({
'name': 'Test Campus',
'code': 'TSTC',
'company_id': self.company.id,
})
self.level = self.env['education.academic.level'].create({
'name': 'Undergraduate',
'code': 'UG',
'company_id': self.company.id,
})
self.department = self.env['education.department'].create({
'name': 'Computer Science',
'code': 'CS',
'campus_id': self.campus.id,
})
self.academic_year = self.env['education.academic.year'].create({
'name': '2025-2026',
'code': 'AY2025',
'start_date': '2025-06-01',
'end_date': '2026-05-31',
'company_id': self.company.id,
'state': 'draft',
})
self.academic_term = self.env['education.academic.term'].create({
'name': 'Semester 1',
'code': 'SEM1',
'academic_year_id': self.academic_year.id,
'start_date': '2025-06-01',
'end_date': '2025-09-30',
'sequence': 1,
'company_id': self.company.id,
})
self.program = self.env['education.program'].create({
'name': 'B.Tech in Computer Science',
'code': 'BTECH-CS',
'level_id': self.level.id,
'department_id': self.department.id,
'duration': 4,
'duration_unit': 'years',
'company_id': self.company.id,
})
self.batch = self.env['education.batch'].create({
'name': 'Batch 2025 Test', 'code': 'B2025T',
})
self.semester = self.env['education.semester'].create({
'name': 'Semester 1 Test', 'code': 'SEM1T',
})
self.section = self.env['education.section'].create({
'name': 'Section A Test', 'code': 'SEC-AT',
})
def test_student_create(self):
student = self.env['education.student'].create({
'first_name': 'John',
'last_name': 'Doe',
'name': 'John Doe',
'student_id': 'STD-1001',
'campus_id': self.campus.id,
'department_id': self.department.id,
'program_id': self.program.id,
'level_id': self.level.id,
'academic_year_id': self.academic_year.id,
'academic_term_id': self.academic_term.id,
'batch_id': self.batch.id,
'semester_id': self.semester.id,
'section_id': self.section.id,
'company_id': self.company.id,
})
self.assertTrue(student.admission_number)
self.assertEqual(student.status, 'draft')
def test_student_academic_validation(self):
with self.assertRaises(Exception):
self.env['education.student'].create({
'first_name': 'Jane',
'last_name': 'Smith',
'name': 'Jane Smith',
'student_id': 'STD-1002',
'campus_id': self.campus.id,
'department_id': self.department.id,
'program_id': self.program.id,
'level_id': self.level.id,
'academic_year_id': self.academic_year.id,
'academic_term_id': self.academic_term.id,
'company_id': self.company.id,
})
self.env.flush_all()
def test_student_status_transition(self):
student = self.env['education.student'].create({
'first_name': 'Alice',
'last_name': 'Brown',
'name': 'Alice Brown',
'student_id': 'STD-1003',
'campus_id': self.campus.id,
'department_id': self.department.id,
'program_id': self.program.id,
'level_id': self.level.id,
'academic_year_id': self.academic_year.id,
'academic_term_id': self.academic_term.id,
'batch_id': self.batch.id,
'semester_id': self.semester.id,
'section_id': self.section.id,
'company_id': self.company.id,
})
student.action_admit()
self.assertEqual(student.status, 'admitted')
student.action_activate()
self.assertEqual(student.status, 'active')
student.action_graduate()
self.assertEqual(student.status, 'graduated')