from odoo import _, models from odoo.exceptions import UserError class McStudent(models.Model): _inherit = "mc.student" def action_view_timetable(self): self.ensure_one() enrollment = self.env["mc.enrollment"].search([ ("student_id", "=", self.id), ("state", "=", "active"), ], limit=1) if not enrollment: raise UserError(_("%s has no active enrollment.") % self.name) return { "type": "ir.actions.act_window", "name": "Timetable - %s" % self.name, "res_model": "mc.timetable.slot", "view_mode": "list,form", "domain": [("batch_id", "=", enrollment.batch_id.id)], "context": {"search_default_group_weekday": 1}, }