shcool/yuthon_school/models/exam.py
2026-08-03 11:07:03 +08:00

72 lines
1.7 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 Exam(models.Model):
_name = 'yuthon.school.exam'
_description = '训练考核'
_order = 'exam_date desc, id'
name = fields.Char(
string='考核名称',
required=True,
help='Odoo 18 模块开发单元测验',
)
course_id = fields.Many2one(
'yuthon.school.course',
string='课程',
ondelete='restrict',
)
student_id = fields.Many2one(
'yuthon.school.student',
string='学生',
required=True,
ondelete='cascade',
)
exam_type = fields.Selection(
[('quiz', '测验'), ('practice', '练习'),
('midterm', '期中'), ('final', '期末')],
string='考核类型',
default='quiz',
)
exam_date = fields.Date(
string='考核日期',
)
score = fields.Float(
string='得分',
default=0.0,
)
total_score = fields.Float(
string='满分',
default=100.0,
)
pass_score = fields.Float(
string='及格线',
default=60.0,
)
state = fields.Selection(
[('pending', '待考'), ('done', '已考')],
string='状态',
default='pending',
)
is_pass = fields.Boolean(
string='是否及格',
compute='_compute_is_pass',
store=True,
)
note = fields.Text(
string='评语',
)
active = fields.Boolean(
string='启用',
default=True,
)
@api.depends('score', 'pass_score')
def _compute_is_pass(self):
for record in self:
record.is_pass = bool(record.score >= record.pass_score)
def action_mark_done(self):
"""标记已考"""
self.write({'state': 'done'})