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

134 lines
6.5 KiB
Python

from odoo import models, fields, api, exceptions, _
class YuthonDutyManagement(models.Model):
_name = 'yuthon.duty.management'
_description = "组织绩效"
_rec_name = 'name'
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('指标失效时间')
assessment_department_id = fields.Many2one("hr.department", string="被考核部门")
index_statu = fields.Selection([('work', '生效'), ('void', '作废')], '状态', required=True)
# 绩效考核
performance_kpi_ids = fields.One2many('yuthon.kpi.line', 'performance_kpi_id', string="KPI")
performance_gs_ids = fields.One2many('yuthon.gs.line', 'performance_gs_id', string="GS")
organization_ids = fields.One2many('yuthon.role.detail.lines', 'organization_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
'organization_id': performance.id, # 建立关联关系
'index_statu': performance.index_statu,
'assessment_time': performance.assessment_time,
'performance_type':'organize'
})
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([('organization_id', '=', performance.id)])
tasks.write({
'name': performance.name,
'index_statu': performance.index_statu,
'assessment_time': performance.assessment_time,
})
return result
class YuthonKpiLine(models.Model):
_name = 'yuthon.kpi.line'
_description = "KPI明细行"
# 链接部门责任书和变更菜单
performance_kpi_id = fields.Many2one('yuthon.duty.management', string="KPI")
change_duty_kpi_id = fields.Many2one('yuthon.duty.approval', string="KPI变更明细")
#
# KPI
# 指标名称
index_name_id = fields.Many2one('yuthon.index.management')
duty_index_name = fields.Char(related='index_name_id.index_name', string='指标名称', store=True)#
index_definition_id = fields.Many2one('yuthon.index.management')
duty_index_definition = fields.Text(related='index_definition_id.index_definition', string="指标定义")
#
# index_id = fields.Many2one('yuthon.index.management')
# duty_index_type = fields.Selection(related='index_id.compute_type', string='计算类别', store=True)
#
# in_charge_role_id = fields.Many2one('yuthon.index.management')
# in_charge_role = fields.Many2one('soong.user.role', related='in_charge_role_id.in_charge_role', string='角色')
#
# duty_employee_id = fields.Many2one('yuthon.index.management')
# employee_id = fields.Many2one('hr.employee', related='duty_employee_id.employee_id', string="员工", store=True)
#半年考核任务
half_floor_limit = fields.Float('底限值')
half_benchmark_value = fields.Float('基准值')
half_top_limit = fields.Float('努力制')
#年考核任务
year_floor_limit = fields.Float('底限值1')
year_benchmark_value = fields.Float('基准值1')
year_top_limit = fields.Float('努力制1')
#月度考核任务
month_floor_limit = fields.Float('底限值')
month_benchmark_value = fields.Float('基准值')
month_top_limit = fields.Float('努力制')
#季度考核任务
quarter_floor_limit = fields.Float('底限值')
quarter_benchmark_value = fields.Float('基准值')
quarter_top_limit = fields.Float('努力制')
unit_compute = fields.Char('计算单位')
weight = fields.Char(string="权重%")
# compute_method = fields.Char(string="计算方法")
#
#
class YuthonGsLine(models.Model):
_name = 'yuthon.gs.line'
_description = "GS明细行"
#
# # 链接部门责任书和变更菜单
performance_gs_id = fields.Many2one('yuthon.duty.management', string="GS")
change_duty_gs_id = fields.Many2one('yuthon.duty.approval', string="GS变更明细")
# # index_duty_gs_id = fields.Many2one('yuthon.index.management', string="GS变更明细")
# # 指标名称
index_name_id = fields.Many2one('yuthon.index.management')
work_task = fields.Char(related='index_name_id.index_name', string="工作任务")
#
compute_act = fields.Char(string="计划安排及具体措施/行动")
node_target = fields.Char(string="节点目标")
quality_objectives = fields.Char(string="质量目标")
node_target1 = fields.Char(string="节点目标")
quality_objectives1 = fields.Char(string="质量目标")
node_target2 = fields.Char(string="节点目标")
quality_objectives2 = fields.Char(string="质量目标")
# index_id = fields.Many2one('yuthon.index.management', string='Index')
# duty_index_type = fields.Selection(related='index_id.compute_type', string='计算类别', store=True)
#
# in_charge_role_id = fields.Many2one('yuthon.index.management')
# in_charge_role = fields.Many2one('soong.user.role', related='in_charge_role_id.in_charge_role', string='角色')
#
# duty_employee_id = fields.Many2one('yuthon.index.management')
# employee_id = fields.Many2one('hr.employee', string="员工", related='duty_employee_id.employee_id', store=True)
#
weight = fields.Char(string="权重%")