from odoo.tests.common import TransactionCase, tagged @tagged('post_install', '-at_install') class TestSchoolAttendance(TransactionCase): def setUp(self): super().setUp() self.term = self.env['community.school.term'].create({ 'name': 'Fall 2030', 'start_date': '2030-09-01', 'end_date': '2030-12-15', }) self.level = self.env['community.school.level'].create({'name': 'Beginner', 'code': 'ATT-BEG'}) self.klass = self.env['community.school.class'].create({ 'level_id': self.level.id, 'term_id': self.term.id, }) self.parent = self.env['res.partner'].create({'name': 'Attendance Parent', 'email': 'parent@example.com'}) self.child = self.env['res.partner'].create({'name': 'Attendance Child'}) self.student = self.env['community.school.student'].create({ 'partner_id': self.child.id, 'parent_partner_id': self.parent.id, }) self.enrollment = self.env['community.school.enrollment'].create({ 'student_id': self.student.id, 'class_id': self.klass.id, }) def test_absence_queues_mail_to_parent(self): mail_count_before = self.env['mail.mail'].search_count([]) attendance = self.env['community.school.attendance'].create({ 'enrollment_id': self.enrollment.id, 'date': '2030-09-08', 'state': 'absent', }) attendance._send_absence_notice() mail_count_after = self.env['mail.mail'].search_count([]) self.assertGreater(mail_count_after, mail_count_before) def test_present_attendance_does_not_require_notice(self): attendance = self.env['community.school.attendance'].create({ 'enrollment_id': self.enrollment.id, 'date': '2030-09-08', 'state': 'present', }) self.assertEqual(attendance.state, 'present') def test_at_risk_flag(self): self.env['ir.config_parameter'].sudo().set_param('community_school.at_risk_attendance_threshold', '70') for i, state in enumerate(['absent', 'absent', 'present']): self.env['community.school.attendance'].create({ 'enrollment_id': self.enrollment.id, 'date': f'2030-09-0{i + 1}', 'state': state, }) self.assertTrue(self.enrollment.is_at_risk, "1/3 present should be below a 70% threshold") def test_unique_attendance_per_enrollment_and_date(self): self.env['community.school.attendance'].create({ 'enrollment_id': self.enrollment.id, 'date': '2030-09-08', 'state': 'present', }) with self.assertRaises(Exception): self.env['community.school.attendance'].create({ 'enrollment_id': self.enrollment.id, 'date': '2030-09-08', 'state': 'absent', })