shcool/yuthon_school/models/organization.py
2026-07-28 18:50:48 +08:00

168 lines
3.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from odoo import fields, models, api
class School(models.Model):
_name = 'yuthon.school.school'
_description = '学校'
name = fields.Char(
string='学校名称',
required=True,
)
address = fields.Char(
string='地址',
)
phone = fields.Char(
string='联系电话',
)
principal = fields.Char(
string='校长',
)
class_ids = fields.One2many(
'yuthon.school.class',
'school_id',
string='班级',
)
class_count = fields.Integer(
string='班级数',
compute='_compute_counts',
)
teacher_ids = fields.One2many(
'yuthon.school.teacher',
'school_id',
string='教师',
)
teacher_count = fields.Integer(
string='教师数',
compute='_compute_counts',
)
active = fields.Boolean(
string='启用',
default=True,
)
@api.depends('class_ids', 'teacher_ids')
def _compute_counts(self):
for record in self:
record.class_count = len(record.class_ids)
record.teacher_count = len(record.teacher_ids)
class SchoolClass(models.Model):
_name = 'yuthon.school.class'
_description = '班级'
name = fields.Char(
string='班级名称',
required=True,
)
school_id = fields.Many2one(
'yuthon.school.school',
string='所属学校',
required=True,
ondelete='cascade',
)
teacher_id = fields.Many2one(
'yuthon.school.teacher',
string='班主任',
)
grade = fields.Char(
string='年级',
)
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)
class Teacher(models.Model):
_name = 'yuthon.school.teacher'
_description = '老师'
name = fields.Char(
string='姓名',
required=True,
)
school_id = fields.Many2one(
'yuthon.school.school',
string='所属学校',
required=True,
ondelete='cascade',
)
phone = fields.Char(
string='联系电话',
)
subject = fields.Char(
string='教授方向',
help='Odoo 模型开发、视图开发、部署运维等',
)
class_ids = fields.One2many(
'yuthon.school.class',
'teacher_id',
string='负责班级',
)
active = fields.Boolean(
string='启用',
default=True,
)
class Student(models.Model):
_name = 'yuthon.school.student'
_description = '学生'
name = fields.Char(
string='姓名',
required=True,
)
student_no = fields.Char(
string='学号',
)
class_id = fields.Many2one(
'yuthon.school.class',
string='所属班级',
ondelete='restrict',
)
school_id = fields.Many2one(
'yuthon.school.school',
string='所属学校',
related='class_id.school_id',
store=True,
)
gender = fields.Selection(
[('male', ''), ('female', '')],
string='性别',
)
phone = fields.Char(
string='联系电话',
)
enrollment_date = fields.Date(
string='入学日期',
)
elective_ids = fields.Many2many(
'yuthon.school.elective',
'yuthon_elective_student_rel',
'student_id',
'elective_id',
string='已选选修课',
)
active = fields.Boolean(
string='启用',
default=True,
)