# pyrefly: ignore [missing-import] from odoo.tests.common import TransactionCase # pyrefly: ignore [missing-import] from odoo.addons.education_dashboard.controllers.main import EducationDashboardController class TestEducationDashboard(TransactionCase): def setUp(self): super(TestEducationDashboard, self).setUp() self.controller = EducationDashboardController() # Setup master records self.campus = self.env['education.campus'].create({'name': 'Dash Campus', 'code': 'DC'}) self.department = self.env['education.department'].create({'name': 'Dash Dept', 'code': 'DD', 'campus_id': self.campus.id}) self.level = self.env['education.academic.level'].create({'name': 'Dash Level', 'code': 'DL'}) self.program = self.env['education.program'].create({'name': 'Dash Prog', 'code': 'DP', 'department_id': self.department.id, 'level_id': self.level.id}) self.year = self.env['education.academic.year'].create({'name': 'Dash Year', 'code': 'DY', 'start_date': '2026-01-01', 'end_date': '2026-12-31'}) self.term = self.env['education.academic.term'].create({'name': 'Dash Term', 'code': 'DT', 'academic_year_id': self.year.id, 'start_date': '2026-01-01', 'end_date': '2026-06-30'}) self.batch = self.env['education.batch'].create({'name': 'Dash Batch', 'code': 'DB'}) self.semester = self.env['education.semester'].create({'name': 'Dash Sem', 'code': 'DS'}) self.section = self.env['education.section'].create({'name': 'Dash Sec', 'code': 'DSEC'}) # Student self.student = self.env['education.student'].create({ 'first_name': 'Dashboard', 'last_name': 'TestStudent', 'student_id': 'DASHSTU1', 'admission_number': 'DASHADM1', 'roll_number': 'DASHRL1', 'campus_id': self.campus.id, 'department_id': self.department.id, 'program_id': self.program.id, 'level_id': self.level.id, 'academic_year_id': self.year.id, 'academic_term_id': self.term.id, 'batch_id': self.batch.id, 'semester_id': self.semester.id, 'section_id': self.section.id, 'status': 'active', }) def test_dashboard_controller_kpis(self): """Test that dashboard JSON controller returns valid and accurate stats""" # Test default/no filter KPIs kpi_data = self.controller.get_dashboard_kpis(env=self.env) self.assertGreaterEqual(kpi_data['total_students'], 1) self.assertGreaterEqual(kpi_data['active_students'], 1) self.assertEqual(kpi_data['admissions'], 0) self.assertGreaterEqual(kpi_data['years_count'], 1) self.assertGreaterEqual(kpi_data['programs_count'], 1) # Test filtering by specific campus kpi_filtered = self.controller.get_dashboard_kpis(campus_id=self.campus.id, env=self.env) self.assertEqual(kpi_filtered['total_students'], 1) # Test filtering by dummy campus (should return 0) kpi_empty = self.controller.get_dashboard_kpis(campus_id=9999, env=self.env) self.xlsx_file = None # or anything self.assertEqual(kpi_empty['total_students'], 0)