Files
gzth/yuthon_performance/models/yuthon_employee_performance.py
T
2025-04-27 21:03:48 +08:00

81 lines
3.8 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_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='组织绩效考核角色明细行')
in_charge_role_id = fields.Many2one('soong.user.role', string='角色')
employee_ids = fields.Many2many('hr.employee', string='人员', compute='_compute_employee_ids', store=True)
weight = fields.Float(string="权重" )
@api.depends('in_charge_role_id')
def _compute_employee_ids(self):
for record in self:
if record.in_charge_role_id:
employee_user_role_ids = self.env['hr.employee'].search(
['|', ('user_role_id', '=', record.in_charge_role_id.id),
('user_role_ids', 'in', record.in_charge_role_id.id)])
record.employee_ids = employee_user_role_ids.ids