yun_product/yuthon_salary/models/class_hour.py
2026-07-30 19:56:43 +08:00

86 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields, api
class ClassHour(models.Model):
"""课时记录 - 记录教职工的授课课时"""
_name = 'yuthon.class.hour'
_description = '课时记录'
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = 'date desc, id desc'
name = fields.Char(string='课时编号', required=True, copy=False, readonly=True, default='新建')
employee_id = fields.Many2one('hr.employee', string='授课教师', required=True)
department_id = fields.Many2one('hr.department', string='所属部门', related='employee_id.department_id', store=True)
# 授课信息
date = fields.Date(string='授课日期', required=True, default=fields.Date.today)
subject = fields.Char(string='科目', required=True)
grade = fields.Char(string='年级/班级')
class_type = fields.Selection([
('normal', '常规课'),
('overtime', '超课时'),
('weekend', '周末课'),
('holiday', '节假日课'),
('makeup', '补课'),
('exam', '考试监考'),
('activity', '课外活动'),
], string='课程类型', required=True, default='normal')
# 课时计算
hours = fields.Float(string='课时数', required=True, default=1.0)
rate = fields.Float(string='课时费标准(元/课时)', required=True, default=0.0)
amount = fields.Float(string='课时费金额', compute='_compute_amount', store=True)
# 状态
state = fields.Selection([
('draft', '草稿'),
('submitted', '已提交'),
('approved', '已确认'),
('paid', '已发薪'),
], string='状态', default='draft', tracking=True)
# 关联薪资单
salary_slip_id = fields.Many2one('yuthon.salary.slip', string='关联薪资单', readonly=True)
note = fields.Text(string='备注')
company_id = fields.Many2one('res.company', string='学校', default=lambda self: self.env.company)
@api.depends('hours', 'rate')
def _compute_amount(self):
for record in self:
record.amount = record.hours * record.rate
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get('name', '新建') == '新建':
vals['name'] = self.env['ir.sequence'].next_by_code('yuthon.class.hour') or '新建'
return super(ClassHour, self).create(vals_list)
def action_submit(self):
self.write({'state': 'submitted'})
def action_approve(self):
self.write({'state': 'approved'})
def action_draft(self):
self.write({'state': 'draft'})
@api.onchange('employee_id', 'class_type')
def _onchange_employee_class_type(self):
if self.employee_id and self.employee_id.user_id:
salary_record = self.env['yuthon.employee.salary'].search([
('employee_id', '=', self.employee_id.id),
('state', '=', 'active')
], limit=1, order='id desc')
if salary_record:
if self.class_type == 'normal':
self.rate = salary_record.class_hour_rate_normal
elif self.class_type == 'overtime':
self.rate = salary_record.class_hour_rate_overtime
elif self.class_type == 'weekend':
self.rate = salary_record.class_hour_rate_weekend
elif self.class_type == 'holiday':
self.rate = salary_record.class_hour_rate_holiday