odoo_18_Education_management/models/school_course_assignment.py

36 lines
1.2 KiB
Python
Raw Normal View History

2025-07-29 05:25:05 +00:00
from odoo import models, fields,api
from odoo.exceptions import UserError
class SchoolCourseAssignment(models.Model):
_name = 'school.course.assignment'
_description = 'Course Assignment'
course_id = fields.Many2one('school.course', string='Course', ondelete='cascade')
type = fields.Char(string='Assignment Type')
weightage = fields.Float(string='Weightage')
teacher = fields.Many2one('res.users', string='Teacher')
class_id = fields.Many2one('school.class', string='Class')
subject_id = fields.Many2one('school.subject', string='Subject', ondelete='cascade', required=True)
assignment_count = fields.Integer(
string="No. of Assignments",
compute="_compute_assignment_count",
store=False,
)
is_completed = fields.Selection([
('yes', 'Completed'),
('no', 'Not Completed')
], string='Status', default='no')
due_date = fields.Date(string='Due Date')
@api.depends('course_id')
def _compute_assignment_count(self):
for rec in self:
if rec.course_id:
rec.assignment_count = self.search_count([('course_id', '=', rec.course_id.id)])
else:
rec.assignment_count = 0
2025-08-06 09:23:00 +00:00