from odoo import fields, models class CommunitySchoolAttendance(models.Model): _name = 'community.school.attendance' _description = 'School Attendance' _order = 'date desc, id desc' enrollment_id = fields.Many2one('community.school.enrollment', required=True, ondelete='cascade') class_id = fields.Many2one(related='enrollment_id.class_id', store=True) date = fields.Date(required=True, default=fields.Date.context_today) state = fields.Selection( [ ('present', 'Present'), ('absent', 'Absent'), ('late', 'Late'), ('excused', 'Excused'), ], default='present', required=True, ) notes = fields.Char() _enrollment_date_uniq = models.Constraint( 'unique(enrollment_id, date)', 'Attendance for this student on this date is already recorded.', ) def _send_absence_notice(self): self.ensure_one() template = self.env.ref('community_school.mail_template_absence_notice', raise_if_not_found=False) if template: template.send_mail(self.id, force_send=False)