shcool/yuthon_salary/models/class_teacher_allowance.py
2026-07-30 19:56:44 +08:00

105 lines
4.4 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields, api
class ClassTeacherAllowance(models.Model):
"""班主任津贴 - 管理班主任的月度津贴"""
_name = 'yuthon.class.teacher.allowance'
_description = '班主任津贴'
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = 'year desc, month 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)
# 班级信息
class_name = fields.Char(string='班级名称', required=True)
grade_level = fields.Selection([
('junior', '低年级'),
('middle', '中年级'),
('senior', '高年级'),
('junior_high', '初中'),
('senior_high', '高中'),
], string='年级段')
student_count = fields.Integer(string='学生人数', default=0)
# 考核评分
year = fields.Integer(string='年度', required=True, default=lambda self: fields.Date.today().year)
month = fields.Integer(string='月份', required=True, default=lambda self: fields.Date.today().month)
# 津贴构成
base_allowance = fields.Float(string='基础津贴', required=True, default=0.0)
student_count_bonus = fields.Float(string='学生人数补贴', default=0.0)
performance_bonus = fields.Float(string='绩效奖金', default=0.0)
special_allowance = fields.Float(string='特殊补贴', default=0.0)
deduction = fields.Float(string='扣款', default=0.0)
total_amount = fields.Float(string='津贴合计', compute='_compute_total', store=True)
# 考核维度
discipline_score = fields.Float(string='纪律管理评分', default=100.0)
hygiene_score = fields.Float(string='卫生管理评分', default=100.0)
activity_score = fields.Float(string='活动组织评分', default=100.0)
parent_score = fields.Float(string='家长沟通评分', default=100.0)
overall_score = fields.Float(string='综合评分', compute='_compute_score', 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('base_allowance', 'student_count_bonus', 'performance_bonus', 'special_allowance', 'deduction')
def _compute_total(self):
for record in self:
record.total_amount = (
record.base_allowance +
record.student_count_bonus +
record.performance_bonus +
record.special_allowance -
record.deduction
)
@api.depends('discipline_score', 'hygiene_score', 'activity_score', 'parent_score')
def _compute_score(self):
for record in self:
record.overall_score = (
record.discipline_score +
record.hygiene_score +
record.activity_score +
record.parent_score
) / 4.0
@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.teacher.allowance') or '新建'
return super(ClassTeacherAllowance, 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')
def _onchange_employee(self):
if self.employee_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:
self.base_allowance = salary_record.class_teacher_allowance