EMS

Technical Reference: Attendance reports

Overview

Two ways to consult ems.attendance_session_line, which always show the same data:

Both take what the user may consult from one method, ems.attendance_session_line._get_reports_domain() (issue #633). Before that, the screen and the wizard decided it each on their own (the wizard from ems.teaching, the screen from the attendance templates), and Guidance could read every student’s attendance on the screen but only pick its own pupils in the wizard.

Module files: models/attendance/attendance_reports.py (wizard + report data models), models/attendance/attendance_session.py (scope and stored fields on ems.attendance_session_line), views/attendance/attendance_reports/{wizard,menu,analysis_views}.xml, reports/attendance/{group,student,subject}.xml + reports/attendance/templates/{sumary_table,details_table,detail_section}.xml, static/src/views/attendance_report_analysis/ (pivot/graph extensions, lazy-loaded), static/src/js/backend/attendance_report_print.js + attendance_report_analysis_cog_menu.js + static/src/xml/backend/attendance_report_analysis_cog_menu.xml.


Scope: who sees what

_get_reports_domain() returns the lines of the current course (session_active) and, unless the user sees the whole centre, only those reached through the chain of command, never by role alone:

Who Lines Mechanism
Teacher The subjects they teach: the attendance templates they are a teacher of. A roll-call taken on guard duty or as a substitute belongs to the template’s teacher, not to whoever took it ('template_teacher_ids.user_id', '=', uid)
Tutor Every subject of their students ('student_id.tutor_id.tutor_scope_user_ids', '=', uid); a student’s tutor is their main group’s (res.partner.tutor_id)
Department / Seminar Chief The students of the tutors below them, plus every student of the studies their department manages The tutor scope above walks parent_id up from the tutor (issue #483); ('student_group_id', 'in', <groups managed by the user's departments>) (issue #622)
Head of Studies / Deputy The same two ways: the tutors below them, and the studies of their area (the area is a top-level department they manage; child_of covers the departments under it) As above
Director, administrator, Guidance, Coexistence, Secretariat The whole centre _user_sees_whole_centre()

_user_sees_whole_centre() checks ems.group_director (the academic administrator implies it), ems.group_orientation, ems.group_coexistence, ems.group_secretary and ems.group_secretary_admin. It deliberately does not check ems.group_student_data_reader: the Head of Studies implies it to read every student’s file (issue #448), but their attendance reports cover their own area.

The managed groups come from two shared helpers: hr.department._headed_by(users) (the departments the users chief as Department Chief or Seminar Chief) and ems.group._managed_by_departments_domain(departments) (the groups whose study, or whose main groups’ study for a reinforcement group, is managed by one of those departments or a sub-department). Both are also used by the notices’ department scope (notice_department_scope.py). The group ids are resolved under sudo(), so the group and study record rules never narrow them.

This is the same “two ways” criterion the guard duty board uses to decide who manages an absence (ems.course._is_absence_manager): the absent teacher’s chain of command, and the chiefs of the department managing the group. A study with no managing department (ems.study.managing_department_id empty) is only reached through the tutors’ chain.

flowchart TD
    U[User] --> W{_user_sees_whole_centre?}
    W -- yes --> A[session_active lines]
    W -- no --> D["session_active lines AND (<br/>template teacher = user<br/>OR student's tutor scope has user<br/>OR student_group in groups managed by the user's departments)"]
    A --> P[Reports screen domain]
    D --> P
    A --> Z[Wizard dropdowns and PDF lines]
    D --> Z

Data model

erDiagram
    ems_attendance_template ||--o{ ems_attendance_schedule : "attendance_schedule_ids"
    ems_attendance_schedule ||--o{ resource_calendar_attendance : "calendar_attendance_ids"
    ems_attendance_schedule ||--o{ ems_attendance_session_header : "attendance_session_ids"
    ems_attendance_session_header ||--o{ ems_attendance_session_line : "attendance_session_id"
    ems_attendance_session_line }o--|| ems_attendance_status : "status_id"
    ems_attendance_session_line }o--o| res_partner : "student_id"
    ems_attendance_report_wizard ..> ems_attendance_session_line : "_get_scope_lines()"

Stored fields on ems.attendance_session_line, so the screen can group and filter without joins and without going through the session header’s record rules (a teacher only reads their own headers):

Topic: a subject split into parts taught apart

A schedule block (resource.calendar.attendance) can carry a free-text topic (issue #428): a CFGB module taught in parts by different teachers (e.g. Ciències aplicades I: Physical Education and Maths; Comunicació i ciències socials I: English and Catalan/Spanish). For attendance, each topic is a subject of its own:


Attendance reports screen (pivot/graph)

action_attendance_report_analysis opens the lines in pivot,graph (pivot first), with no list view. It is only reached through ems.attendance_session_line._get_reports_action(), called by:

_get_reports_action() reads the act_window (sudo().read()), sets domain = _get_reports_domain() (a Python list: the read act_window domain is a raw string), context['pivot_measures'] = ['absence_rate', 'strike_count', '__count'], context['graph_measure'] = 'absence_rate' and context['active_test'] = True, and, for whoever doesn’t see the whole centre, turns on the removable My subjects filter ([('template_teacher_ids.user_id', '=', uid)]).


PDF wizard

One ems.attendance_report_wizard with report_type (group / student / subject); only the fields of the chosen type are shown and required. Every list it offers and every line it prints comes from the scope above:

Report Selection Lines
By student student_id _get_student_lines(): that student’s lines in scope
By group group_id _get_group_lines(): student_group_id = the group, with a student
By subject subject_label (a Selection of the labels in scope) + group_ids (prefilled with every group having it, removable) _get_subject_lines(): subject_label = the choice, student_group_id in the groups, with a student

Views

View File
PDF wizard form views/attendance/attendance_reports/wizard.xml
Pivot/graph/search views/attendance/attendance_reports/analysis_views.xml
Actions, Attendance → Reports menu, action_attendance_reports_open views/attendance/attendance_reports/menu.xml
PDF templates reports/attendance/{group,student,subject,session}.xml + reports/attendance/templates/{sumary_table,details_table,detail_section}.xml
Print button (pivot/graph js_class) static/src/views/attendance_report_analysis/attendance_report_analysis_views.{js,xml}
⚙ Actions entry static/src/js/backend/attendance_report_analysis_cog_menu.js + static/src/xml/backend/attendance_report_analysis_cog_menu.xml

Access control

Role PDF wizard (ems.attendance_report_wizard) Lines shown (screen and PDFs)
Teacher read/write/create Their own subjects (My subjects on by default)
Tutor read/write/create Plus every subject of their students
Department / Seminar Chief read/write/create Plus the students of the tutors below them and of the studies their department manages
Head of Studies / Deputy read/write/create Plus the students of the tutors below them and of the studies of their area
Director, administrator read/write/create Whole centre
Guidance, Coexistence read/write/create (as teachers: the post is a teaching one) Whole centre
Secretary (+ admin) read/write/create Whole centre

The record rules on the lines are not what narrows this down: every teacher can read every line (rule_attendance_session_line_teacher_all_read, needed to justify absences). The scope is the domain above, applied identically by both screens.

Testing