Files
gzth/yuthon_hr_employee_approval/models/yuthon_recruitment_approval.py
T
2025-08-04 14:48:59 +08:00

80 lines
3.7 KiB
Python

from numpy.f2py.rules import defmod_rules
from odoo import models, fields, api
from odoo.exceptions import UserError
class YuthonRecruitmentApproval(models.Model):
_name = 'yuthon.recruitment.approval'
_description = '招聘需求申请表'
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
name = fields.Char(string='标题')
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_recruitment_approval_code'))
reason = fields.Text(string="正文")
recruitment_ids = fields.One2many('hr.job', 'recruitment_approval_id', string="招聘申请")
is_issues = fields.Boolean(string='是否上会')
issues_result = fields.Html(string="会议结果")
related_issues_id = fields.Many2one('issue.library', string="关联议题")
documents_ids = fields.Many2many('ir.attachment', string='议题附件')
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
default='normal')
active = fields.Boolean('Active', default=True, tracking=True)
work_end = fields.Boolean(string="结束")
def _get_default_name_title(self):
return self._description if self._description else self._name
name_title = fields.Char(default=_get_default_name_title)
self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])])
@api.onchange('is_issues')
def _onchange_is_issues(self):
if self.is_issues:
issue_id = self.env['issue.library'].create({'name': self.name})
self.related_issues_id = issue_id.id
workflow_record_id = self.env["soong.workflow.record"].search(
[("res_model", "=", self._name), ("res_id", "=", self.id)])
self.env['issue.library.approval.line'].create({
'issue_library_id': issue_id.id,
'workflow_record_id': workflow_record_id.id,
'approval_type': workflow_record_id.workflow_id.id,
'code': self.code,
'approval_date': fields.Datetime.now(),
})
def put_time_failure(self):
for record in self:
for recruitment in record.recruitment_ids:
recruitment.website_published = True
@api.onchange('recruitment_ids')
def _onchange_recruitment_ids(self):
name_list = []
if self.recruitment_ids:
for record in self.recruitment_ids:
name_list.append(record.name)
self.name = record.department_id.name +', '.join(name_list)+'的招聘需求申请表'
def write(self, vals):
# 调用父类的 write 方法,先保存数据
res = super(YuthonRecruitmentApproval, self).write(vals)
# 检查是否更新了 no_of_recruitment 字段
if 'recruitment_employees' in vals:
for record in self:
# 遍历 recruitment_ids 中的每个 hr.job 记录
for job in record.recruitment_ids:
# 将 no_of_recruitment 同步到 hr.job 记录中
job.write({'recruitment_employees': record.recruitment_employees})
return res
def open_job_record(self):
return {
"type": "ir.actions.act_window",
"res_model": 'yuthon.index.employee',
"res_id": self.id,
"name": "任职要求详情",
"view_mode": "form",
}