175 lines
8.7 KiB
Python
175 lines
8.7 KiB
Python
from odoo import models, fields, api
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class YuthonPrepareApproval(models.Model):
|
|
_name = 'yuthon.prepare.approval'
|
|
_description = '编制调整需求表'
|
|
_inherit = 'soong.workflow.mixin'
|
|
|
|
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
|
|
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
|
|
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_prepare_approval_code'))
|
|
yuthon_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'), ('thlc', '天河粮储')], string="所属公司")
|
|
name = fields.Char(string='标题')
|
|
reason = fields.Html(string="正文")
|
|
is_issues = fields.Boolean(string='是否上会')
|
|
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
|
notice_documents_ids = fields.Many2many('ir.attachment', string='议题附件')
|
|
adjust_information_ids = fields.One2many('prepare.approval.line', 'prepare_approval_id', string="关联调整信息")
|
|
prepare_approval_line_ids = fields.One2many('new.prepare.approval.line', 'prepare_approval_id', string="关联编制调整需求表行")
|
|
|
|
@api.onchange('adjust_information_ids')
|
|
def onchange_change_index_library_ids(self):
|
|
new_lines = []
|
|
for old in self:
|
|
for new in old.adjust_information_ids:
|
|
new_lines.append((0, 0, {
|
|
'hr_job_id': new.hr_job_id.id,
|
|
'department_id': new.department_id.id,
|
|
'yuthon_company': new.yuthon_company,
|
|
'job_type_id': new.job_type_id.id,
|
|
'compiling_external': new.compiling_external,
|
|
'job_lv_id': new.job_lv_id.id,
|
|
'establishment_quotas': new.establishment_quotas,
|
|
'no_of_employee': new.no_of_employee,
|
|
'missing_number': new.missing_number,
|
|
'compiling_status': new.compiling_status,
|
|
'job_personnel': new.job_personnel,
|
|
'remarks': new.remarks,
|
|
}))
|
|
self.prepare_approval_line_ids = new_lines
|
|
|
|
def put_adjustment_approval(self):
|
|
self.ensure_one()
|
|
for prepare in self.prepare_approval_line_ids:
|
|
prepare.hr_job_id.write({
|
|
'department_id': prepare.department_id.id,
|
|
'yuthon_company': prepare.yuthon_company,
|
|
'job_type_id': prepare.job_type_id.id,
|
|
'compiling_external': prepare.compiling_external,
|
|
'job_lv_id': prepare.job_lv_id.id,
|
|
'establishment_quotas': prepare.establishment_quotas,
|
|
'no_of_employee': prepare.no_of_employee,
|
|
'missing_number': prepare.missing_number,
|
|
'compiling_status': prepare.compiling_status,
|
|
'job_personnel': prepare.job_personnel,
|
|
'remarks': prepare.remarks,
|
|
})
|
|
|
|
@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(),
|
|
})
|
|
elif self.related_issues_id:
|
|
raise UserError("已经创建了相关的上会记录,不能取消勾选")
|
|
|
|
class PrepareApprovalLine(models.Model):
|
|
_name = 'prepare.approval.line'
|
|
_description = '编制调整需求表行'
|
|
|
|
prepare_approval_id = fields.Many2one('yuthon.prepare.approval', string="编制调整需求表")
|
|
hr_job_id = fields.Many2one('hr.job', string='工作岗位')
|
|
department_id = fields.Many2one("hr.department", string="部门")
|
|
yuthon_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'),
|
|
('thlc', '天河粮储')], string="所属公司")
|
|
job_type_id = fields.Many2one('hr.job.type', string="岗位类型")
|
|
compiling_external = fields.Integer(string="编制外人数")
|
|
job_lv_id = fields.Many2one('yuthon.job.lv', string="职级")
|
|
establishment_quotas = fields.Integer(string="编制人数")
|
|
no_of_employee = fields.Integer(string="当前员工数量")
|
|
missing_number = fields.Integer(string="缺编人数", compute='_compute_missing_number')
|
|
compiling_status = fields.Selection([('1', '缺编'), ('2', '满编')], compute="_compute_compiling_status", string="状态")
|
|
job_personnel = fields.Char(string="在岗人员", compute='_compute_job_personnel')
|
|
remarks = fields.Text(string="备注")
|
|
|
|
@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('no_of_employee')
|
|
def _compute_job_personnel(self):
|
|
for rec in self:
|
|
employee_ids = rec.env['hr.employee'].search([('job_id', '=', rec.id)])
|
|
employee_list = [rec.name for rec in employee_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.onchange('is_issues')
|
|
def _onchange_is_issues(self):
|
|
self.write({'is_issues': 'Ture'})
|
|
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(),
|
|
})
|
|
|
|
class NewPrepareApprovalLine(models.Model):
|
|
_name = 'new.prepare.approval.line'
|
|
_description = '新编制调整需求表行'
|
|
|
|
prepare_approval_id = fields.Many2one('yuthon.prepare.approval', string="编制调整需求表")
|
|
hr_job_id = fields.Many2one('hr.job', string='工作岗位')
|
|
department_id = fields.Many2one("hr.department", string="部门")
|
|
yuthon_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'),
|
|
('thlc', '天河粮储')], string="所属公司")
|
|
job_type_id = fields.Many2one('hr.job.type', string="岗位类型")
|
|
compiling_external = fields.Integer(string="编制外人数")
|
|
job_lv_id = fields.Many2one('yuthon.job.lv', string="职级")
|
|
establishment_quotas = fields.Integer(string="编制人数")
|
|
no_of_employee = fields.Integer(string="当前员工数量")
|
|
missing_number = fields.Integer(string="缺编人数",compute='_compute_missing_number')
|
|
compiling_status = fields.Selection([('1', '缺编'), ('2', '满编')], compute="_compute_compiling_status", string="状态")
|
|
job_personnel = fields.Char(string="在岗人员", compute='_compute_job_personnel')
|
|
remarks = fields.Text(string="备注")
|
|
|
|
@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('no_of_employee')
|
|
def _compute_job_personnel(self):
|
|
for rec in self:
|
|
employee_ids = rec.env['hr.employee'].search([('job_id', '=', rec.id)])
|
|
employee_list = [rec.name for rec in employee_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'
|