添加功能

This commit is contained in:
zhouzhou
2024-12-24 10:05:17 +08:00
parent fa4a1469f8
commit fc3a228374
+15 -3
View File
@@ -17,10 +17,10 @@ class YuthonUserRole(models.Model):
create_time = fields.Date(string="创建时间", default=fields.Datetime.today())
end_time = fields.Date(string="结束时间")
parent_id = fields.Many2one('soong.user.role', string='上级角色', index=True)
personnel_ids = fields.Many2many('hr.employee', string='在岗人员', compute='_compute_employee_ids')
personnel = fields.Text(string="在岗人员", compute='_compute_personnel')
personnel_ids = fields.Many2many('hr.employee', string='在岗人员', compute='_compute_employee_ids', store=True)
personnel = fields.Text(string="在岗人员", compute='_compute_personnel', store=True)
employee_ids = fields.One2many('hr.employee', 'user_role_id')
number_people = fields.Integer(string="在岗人数", compute='_compute_number_people')
number_people = fields.Integer(string="在岗人数", compute='_compute_number_people', store=True)
child_ids = fields.One2many('soong.user.role', 'parent_id', string='下级角色', index=True)
yuthon_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'),
('thlc', '天河粮储'), ('thtjbb', '天河投资本部')], string="所属公司", compute='compute_company')
@@ -91,3 +91,15 @@ class YuthonUserRole(models.Model):
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 sync_new(self):
job_ids = self.env["soong.user.role"].browse(self._context.get('active_ids', self._context.get('active_id')))
for job in job_ids:
employee_ids = self.env['hr.employee'].search([('id', 'in', job.personnel_ids.ids)])
for employee_id in employee_ids:
if employee_id.user_role_ids:
current_role_ids = employee_id.user_role_ids.ids
missing_role_ids = [child.id for child in job.child_ids if child.id not in current_role_ids]
if missing_role_ids:
employee_id.user_role_ids = [(4, role_id) for role_id in missing_role_ids]