29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from odoo import models, fields, api
|
|
from odoo.exceptions import ValidationError
|
|
|
|
class TeacherAttendance(models.Model):
|
|
_name = 'school.teacher.attendance'
|
|
_description = 'Teacher Attendance'
|
|
_order = 'date desc'
|
|
|
|
teacher_id = fields.Many2one('res.partner', string='Student')
|
|
date = fields.Date(string='Date', required=True, default=fields.Date.today)
|
|
attendance_status = fields.Selection([
|
|
('present', 'Present'),
|
|
('absent', 'Absent'),
|
|
('on_leave', 'On Leave'),
|
|
('late', 'Late')
|
|
], string='Status', required=True, default='present')
|
|
remarks = fields.Text(string='Remarks')
|
|
|
|
@api.constrains('date', 'teacher_id')
|
|
def _check_duplicate_attendance(self):
|
|
for rec in self:
|
|
existing = self.search([
|
|
('teacher_id', '=', rec.teacher_id.id),
|
|
('date', '=', rec.date),
|
|
('id', '!=', rec.id)
|
|
])
|
|
if existing:
|
|
raise ValidationError("Attendance for this teacher already exists on this date.")
|