metatroncubeswdev c77fb3d0e5 O6: mc_education_exam - grading scales as data, grid entry, report card PDF
Serves Demo Scene 6. mc.grading.scale + mc.grading.interval are pure
data (threshold/letter/point/description rows) - CBSE, ICSE, IB,
Cambridge, Ontario and a plain percentage scale all shipped as data
in data/mc_grading_scale_data.xml, noupdate="1" so a school's own
edits survive a module upgrade. mc.mark.grade resolves via
mc.program.grading_scale_id (new field on mc.program, since grading
board is a per-program concept already carrying "board" from O1) -
the moment this needed an `if board == "CBSE"` anywhere, per
shared/DOMAIN_MODEL.md sec 5, it would have been the wrong design;
verified instead that swapping a program's scale recomputes an
existing mark's grade with zero code involved
(test_changing_scale_recomputes_existing_marks).

Grid mark entry ("whole class on one screen, tab between fields,
keyboard only") is a plain editable list on mc.mark, filtered to one
exam - that native Odoo behavior already gives real Tab-key
navigation with no custom widget. mc.exam.action_enter_marks()
pre-creates a row per actively-enrolled student before opening it
(mirroring O4's bulk-attendance idempotency: creating it again never
duplicates or resets an already-entered mark).

The report card is a real rendered PDF, not just a template read by
inspection - rendered it for Aditya via odoo shell
(report._render_qweb_pdf), pulled the bytes out of the container, and
read the actual PDF: one A4 page, no clipped columns, correct grades
per subject matching the CBSE scale (92->A1, 85->A2, 78->B1, 67->B2,
58->C1), signature block, term correctly resolved. That last part
exposed a real logic bug before it shipped: the term-resolution
method originally preferred "today's date" over "the term with
marks", which would have shown an empty Term 1 when generating the
card *today* even though the demo's graded marks are all in Term 2 -
a report card is generated to review a term's results, typically
after that term's exams are done (often during the *next* term), so
marks-with-data now wins over the calendar, falling back to today's
date only for a student with nothing graded yet.

Attendance summary on the report degrades to None when
mc_education_attendance isn't installed (checked directly, not
assumed) - this module depends on mc_education_base only, matching
"each mc_education_* module installs independently" (CLAUDE.md sec
1.4), while still showing the real summary when both are installed
together for the actual demo.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-11 13:16:49 -04:00

86 lines
3.8 KiB
Python

from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestGrading(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.year = cls.env["mc.academic.year"].create({
"name": "TEST-GRADE-2026-27",
"date_start": "2026-06-01", "date_end": "2027-04-30",
})
cls.term = cls.env["mc.academic.term"].create({
"name": "TEST GRADE Term", "year_id": cls.year.id,
"date_start": "2026-06-01", "date_end": "2026-09-30",
})
cls.scale_a = cls.env["mc.grading.scale"].create({"name": "TEST Scale A"})
cls.env["mc.grading.interval"].create({
"scale_id": cls.scale_a.id, "threshold": 90, "letter": "A1",
})
cls.env["mc.grading.interval"].create({
"scale_id": cls.scale_a.id, "threshold": 75, "letter": "A2",
})
cls.env["mc.grading.interval"].create({
"scale_id": cls.scale_a.id, "threshold": 0, "letter": "F",
})
cls.scale_b = cls.env["mc.grading.scale"].create({"name": "TEST Scale B"})
cls.env["mc.grading.interval"].create({
"scale_id": cls.scale_b.id, "threshold": 50, "letter": "PASS",
})
cls.env["mc.grading.interval"].create({
"scale_id": cls.scale_b.id, "threshold": 0, "letter": "FAIL",
})
cls.program = cls.env["mc.program"].create({
"name": "TEST GRADE Program", "code": "TEST-GRADE-P1", "sequence_no": 1,
"display_label": "Test Grade", "grading_scale_id": cls.scale_a.id,
})
cls.batch = cls.env["mc.batch"].create({
"name": "TEST GRADE Batch", "program_id": cls.program.id, "year_id": cls.year.id,
})
cls.exam = cls.env["mc.exam"].create({
"name": "TEST GRADE Exam", "term_id": cls.term.id, "batch_id": cls.batch.id,
"subject_id": cls.env["mc.subject"].create({"name": "TEST GRADE Subject", "code": "TEST-GRADE-S1"}).id,
"max_marks": 100, "pass_marks": 35, "date": "2026-07-01",
})
partner = cls.env["res.partner"].create({"name": "Grade Test Student"})
cls.student = cls.env["mc.student"].create({
"partner_id": partner.id, "name": "Grade Test Student",
})
def test_scale_picks_highest_matching_threshold(self):
self.assertEqual(self.scale_a.get_grade_interval(95).letter, "A1")
self.assertEqual(self.scale_a.get_grade_interval(90).letter, "A1")
self.assertEqual(self.scale_a.get_grade_interval(89.9).letter, "A2")
self.assertEqual(self.scale_a.get_grade_interval(10).letter, "F")
def test_mark_grade_computed_from_program_scale(self):
mark = self.env["mc.mark"].create({
"exam_id": self.exam.id, "student_id": self.student.id, "marks_obtained": 92,
})
self.assertEqual(mark.grade, "A1")
def test_changing_scale_recomputes_existing_marks(self):
mark = self.env["mc.mark"].create({
"exam_id": self.exam.id, "student_id": self.student.id, "marks_obtained": 60,
})
self.assertEqual(mark.grade, "F") # 60 < 75 threshold under Scale A
self.program.grading_scale_id = self.scale_b.id
self.assertEqual(mark.grade, "PASS") # same 60%, Scale B calls it a pass
def test_no_scale_configured_leaves_grade_blank(self):
self.program.grading_scale_id = False
mark = self.env["mc.mark"].create({
"exam_id": self.exam.id, "student_id": self.student.id, "marks_obtained": 92,
})
self.assertFalse(mark.grade)
def test_marks_out_of_range_rejected(self):
with self.assertRaises(ValidationError):
self.env["mc.mark"].create({
"exam_id": self.exam.id, "student_id": self.student.id, "marks_obtained": 150,
})