24 lines
849 B
Python
24 lines
849 B
Python
from odoo import api, fields, models
|
|
|
|
|
|
class SchoolClass(models.Model):
|
|
"""班级——归属一名班主任(老师),包含若干学生。"""
|
|
|
|
_name = 'yuthon.school.class'
|
|
_description = '班级'
|
|
_order = 'name'
|
|
|
|
name = fields.Char(string='班级名称', required=True, index=True)
|
|
head_teacher_id = fields.Many2one(
|
|
'yuthon.school.teacher', string='班主任', ondelete='set null')
|
|
student_ids = fields.One2many(
|
|
'yuthon.school.student', 'class_id', string='学生')
|
|
student_count = fields.Integer(
|
|
string='学生人数', compute='_compute_student_count', store=True)
|
|
active = fields.Boolean(string='启用', default=True)
|
|
|
|
@api.depends('student_ids')
|
|
def _compute_student_count(self):
|
|
for record in self:
|
|
record.student_count = len(record.student_ids)
|