Files
gzth/yuthon_performance/models/yuthon_employee_performance.py
T
2024-10-20 21:23:34 +08:00

76 lines
3.7 KiB
Python

from odoo import models, fields, api, exceptions, _
from odoo.exceptions import ValidationError, UserError
class YuthonEmployeePerformance(models.Model):
_name = 'yuthon.employee.performance'
_description = '员工绩效(考核任务)'
name = fields.Char('标题')
assessment_time = fields.Char('考核时间', required=True)
cycle = fields.Selection([('monthly', '月度'),
('quarter', '季度'),
('up_half', '上半年'),
('down_half', '下半年'),
('year', '年度'), ], '周期', required=True)
department_id = fields.Many2one("hr.department", string="部门", required=True)
start_index_time = fields.Date('指标生效时间')
end_index_time = fields.Date('指标失效时间')
examiners = fields.Selection([('middle', '中层'),('staff', '普通员工')],string='被考核人')
index_statu = fields.Selection([('work', '生效'), ('void', '作废')], '状态', required=True)
department_within = fields.Float(string="部门内权重")
evaluation_ids = fields.One2many('yuthon.appraisal.line.detail', 'evaluation_id', string='员工绩效')
role_ids = fields.One2many('yuthon.role.detail.lines', 'role_id', string='考核角色')
@api.onchange('assessment_time', 'cycle', 'department_id')
def _onchange_year_department(self):
if self.cycle and self.department_id and self.assessment_time:
cycle_dict = {'monthly': '月度', 'quarter': '季度', 'up_half': '上半年', 'down_half': '下半年',
'year': '年度'}
cycle_display = cycle_dict.get(self.cycle, self.cycle)
self.name = f"{self.assessment_time}{cycle_display}{self.department_id.name}绩效考核"
@api.model_create_multi
def create(self, vals_list):
performance_records = super().create(vals_list)
for performance in performance_records:
self.env['yuthon.assessment.tasks'].create({
'name': performance.name, # 使用创建的 performance 记录的 name
'performance_id': performance.id, # 建立关联关系
'index_statu': performance.index_statu,
'assessment_time': performance.assessment_time,
'performance_type': 'employs'
})
return performance_records
@api.model
def write(self, vals):
result = super().write(vals)
if result:
# 只更新被修改的记录
for performance in self:
tasks = self.env['yuthon.assessment.tasks'].search([('performance_id', '=', performance.id)])
tasks.write({
'name': performance.name,
'index_statu': performance.index_statu,
'assessment_time': performance.assessment_time,
})
return result
class YuthonRoleDetailLines(models.Model):
_name = 'yuthon.role.detail.lines'
_description = "考核角色明细行"
role_id = fields.Many2one('yuthon.employee.performance', string="关联员工绩效(考核任务)")
organization_id = fields.Many2one('yuthon.duty.management', string='组织绩效考核角色明细行')
job_id = fields.Many2one('hr.job', string="考核角色")
employee_id = fields.Many2one('hr.employee', string="人员")
weight = fields.Float(string="权重" )
#
# @api.onchange('role_id', 'weight')
# def _onchange_weight(self):
# if self.role_id and self.weight:
# total_weight = sum(self.search([('role_id', '=', self.role_id.id)]).mapped('weight'))
# if total_weight > 100:
# raise UserError('每个考核任务的权重之和不能大于 100%!')