147 lines
6.3 KiB
Python
147 lines
6.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models, _
|
|
import datetime
|
|
|
|
|
|
class HrJob(models.Model):
|
|
_inherit = "hr.job"
|
|
_order = 'number asc'
|
|
|
|
_sql_constraints = [
|
|
('name_company_uniq', 'unique(name)', 'The name of the job position must be unique per department in company!'),
|
|
('no_of_recruitment_positive', 'CHECK(no_of_recruitment >= 0)', 'The expected number of new employees must be positive.')
|
|
]
|
|
|
|
number = fields.Char(string="序号")
|
|
job_type_id = fields.Many2one('hr.job.type', string="岗位类别")
|
|
start_date = fields.Date(string="生效日期", default=lambda self: fields.Date.today())
|
|
end_date = fields.Date(string="失效日期", default=fields.Date.from_string('2099-01-01'))
|
|
is_enable = fields.Boolean(string="是否启用", default=False, compute='compute_is_enable', store=True)
|
|
compiling_external = fields.Integer(string="编制外人数")
|
|
compiling_status = fields.Selection([('1', '缺编'), ('2', '满编')], compute="_compute_compiling_status", string="状态")
|
|
missing_number = fields.Integer(string="缺编人数", compute='_compute_missing_number')
|
|
establishment_quotas = fields.Integer(string="编制定员")
|
|
job_personnel_ids = fields.Many2many('hr.employee', string='在岗人员', compute='_compute_job_personnel_ids')
|
|
recruitment_employees = fields.Integer(string="招聘人数")
|
|
email = fields.Char(string='邮箱')
|
|
job_personnel = fields.Text(string="在岗人员", compute='_compute_job_personnel')
|
|
remarks = fields.Text(string="备注")
|
|
is_recruitment_status = fields.Boolean(string="招聘状态")
|
|
|
|
#任职要求
|
|
degree = fields.Selection([('high', '高中'), ('junior_college', '大专'), ('bachelor', '本科'),
|
|
('master', '硕士'), ('doctor', '博士')], string="学历")
|
|
sex = fields.Selection([('boy', '男'), ('girl', '女'), ('other', '不限')], string="性别")
|
|
age_start = fields.Integer(string="年龄")
|
|
age_end = fields.Integer(string="年龄")
|
|
political_aspects = fields.Selection([('cpc_dang', '中共党员'), ('nld', '民盟'),
|
|
('league_member', '共青团员'), ('people', '群众')], string="政治面貌")
|
|
professional = fields.Char(string="专业")
|
|
job_title = fields.Char(string="职称")
|
|
admissions = fields.Char(string="执业资格")
|
|
years_of_service = fields.Integer(string="工作年限")
|
|
competency_requirements = fields.Text(string="岗位职责")
|
|
other_notes = fields.Text(string="任职要求")
|
|
function = fields.Text(string="岗位职责")
|
|
|
|
def action_create_new_job(self):
|
|
action = self.env.ref("hr_recruitment.hr_applicant_view_form")
|
|
return {
|
|
"type": "ir.actions.act_window",
|
|
"name": "新建",
|
|
"res_model": "hr.applicant",
|
|
"view_mode": "form",
|
|
"views": [(action.id, "form")],
|
|
"view_id": action.id,
|
|
"target": "main",
|
|
"context":
|
|
{
|
|
'default_job_id': self.id,
|
|
}
|
|
}
|
|
|
|
@api.depends('job_personnel_ids')
|
|
def _compute_job_personnel(self):
|
|
for rec in self:
|
|
employee_list = [job.name for job in rec.job_personnel_ids]
|
|
rec.job_personnel = ','.join(employee_list)
|
|
|
|
@api.depends('establishment_quotas', 'no_of_employee')
|
|
def _compute_compiling_status(self):
|
|
for state in self:
|
|
if state.missing_number > 0:
|
|
state.compiling_status = '1'
|
|
else:
|
|
state.compiling_status = '2'
|
|
|
|
@api.depends('establishment_quotas', 'no_of_employee')
|
|
def _compute_missing_number(self):
|
|
for rec in self:
|
|
if rec.establishment_quotas <= rec.no_of_employee:
|
|
rec.missing_number = 0
|
|
else:
|
|
rec.missing_number = abs(rec.establishment_quotas - rec.no_of_employee)
|
|
|
|
@api.depends('start_date', 'end_date')
|
|
def compute_is_enable(self):
|
|
for rec in self:
|
|
if rec.start_date and rec.end_date:
|
|
if rec.start_date <= fields.Date.today() < rec.end_date:
|
|
rec.is_enable = True
|
|
else:
|
|
rec.is_enable = False
|
|
|
|
def employee_recruitment_time(self):
|
|
for record in self.search([]):
|
|
if record.end_date:
|
|
if record.end_date < fields.Date.today():
|
|
record.is_enable = False
|
|
|
|
def f5_new(self):
|
|
job_ids = self.env["hr.job"].browse(self._context.get('active_ids', self._context.get('active_id')))
|
|
for job in job_ids:
|
|
department_id = self.env['hr.department'].search([('name', '=', job.department_id.name)])
|
|
if department_id:
|
|
job.sudo().write({'department_id': department_id.id if len(department_id) == 1 else department_id[0].id})
|
|
|
|
def f6_new(self):
|
|
job_ids = self.env["hr.job"].browse(self._context.get('active_ids', self._context.get('active_id')))
|
|
for job in job_ids:
|
|
if job.department_id:
|
|
company_id = job.department_id.company_id
|
|
if company_id:
|
|
job.sudo().write(
|
|
{'company_id': company_id})
|
|
|
|
@api.onchange('job_personnel_ids')
|
|
def _onchange_job_personnel_ids(self):
|
|
for job in self:
|
|
for employee in job.job_personnel_ids:
|
|
other_jobs = self.env['hr.job'].search([
|
|
('job_personnel_ids', 'in', [employee.id]),
|
|
('id', '!=', job.id)
|
|
])
|
|
if other_jobs:
|
|
for other_job in other_jobs:
|
|
if employee.id in other_job.job_personnel_ids.ids:
|
|
other_job.job_personnel_ids = [(3, employee.id)]
|
|
if hasattr(employee, 'job_id'):
|
|
employee.job_id = job.id
|
|
|
|
@api.depends('employee_ids.job_id', 'employee_ids.active')
|
|
def _compute_job_personnel_ids(self):
|
|
for job in self:
|
|
active_employees = self.env['hr.employee'].search([
|
|
('job_id', '=', job.id),
|
|
('active', '=', True)
|
|
])
|
|
job.job_personnel_ids = [(6, 0, active_employees.ids)]
|
|
|
|
class HrJobType(models.Model):
|
|
_name = "hr.job.type"
|
|
|
|
name = fields.Char(string="类别名称")
|
|
|
|
|
|
|