diff --git a/soong_workflow/models/soong_workflow_record.py b/soong_workflow/models/soong_workflow_record.py index 7cb356aeb..2077f75c5 100644 --- a/soong_workflow/models/soong_workflow_record.py +++ b/soong_workflow/models/soong_workflow_record.py @@ -130,35 +130,77 @@ class SoongWorkflowRecord(models.Model): _logger.warning(f"Failed to get urgency_level from {record.res_model}: {e}") record.urgency_level = 'normal' - @api.depends('employee_ids', 'soong_state', 'reclaim_state') + @api.depends('employee_ids', 'log_ids', 'log_ids2', 'log_ids.approval_state', 'log_ids.done_by', + 'log_ids2.approval_state', 'log_ids2.done_by') def _compute_is_to_do(self): current_uid = self.env.user.id + current_employee = self.env['hr.employee'].search([('user_id', '=', current_uid)], limit=1) + active_employee_ids = [current_employee.id] if current_employee else [] + emp_to_user = {emp.id: emp.user_id.id for emp in self.env['hr.employee'].search([]) if emp.user_id} for record in self: record.is_to_do = False - condition1 = record.soong_state in ['to_do', 'to_active', 'done'] - condition2 = not record.reclaim_state - condition3 = False - if record.employee_ids: - condition3 = current_uid in record.employee_ids.mapped('user_id.id') - if condition1 and condition2 and condition3: - record.is_to_do = True + record_emp_ids = [emp.id for emp in record.employee_ids if emp.id in active_employee_ids] + if not record_emp_ids: + continue + + # 3. 转换为对应的用户ID列表 + record_user_ids = [emp_to_user[emp_id] for emp_id in record_emp_ids if emp_id in emp_to_user] + if not record_user_ids: + continue + + is_todo = False + # 4.1 检查log_ids:筛选done_by属于当前记录关联用户,且审批状态为0/1的记录 + if record.log_ids: + target_logs = record.log_ids.filtered( + lambda l: l.done_by.id in record_user_ids and l.approval_state in ['0', '1'] + ) + if target_logs: + is_todo = True + + # 4.2 检查log_ids2:如果log_ids没命中,再检查log_ids2 + if not is_todo and record.log_ids2: + target_log2 = record.log_ids2.filtered( + lambda l: l.done_by.id in record_user_ids and l.approval_state in ['0', '1'] + ) + if target_log2: + is_todo = True + record.is_to_do = is_todo def _search_is_to_do(self, operator, value): + """ + 实现is_to_do字段的搜索逻辑 + :param operator: 搜索操作符(=, !=) + :param value: 搜索值(True/False) + :return: 搜索域 + """ current_uid = self.env.user.id - current_employee_ids = self.env['hr.employee'].search([ - ('user_id', '=', current_uid) - ]).ids + current_employee = self.env['hr.employee'].search([('user_id', '=', current_uid)], limit=1) + if not current_employee: + return [('id', '=', False)] # + active_employee_ids = [current_employee.id] + emp_to_user = {emp.id: emp.user_id.id for emp in self.env['hr.employee'].search([]) if emp.user_id} + # - 员工关联:employee_ids在active_employee_ids中 + # - log_ids条件:done_by属于当前用户,且approval_state为0/1 + # - 或 log_ids2条件:done_by属于当前用户,且approval_state为0/1 + log1_domain = [ + ('log_ids.done_by', '=', current_uid), + ('log_ids.approval_state', 'in', ['0', '1']) + ] + log2_domain = [ + ('log_ids2.done_by', '=', current_uid), + ('log_ids2.approval_state', 'in', ['0', '1']) + ] base_domain = [ - ('soong_state', 'in', ['to_do', 'to_active', 'done']), - ('reclaim_state', '=', False), - ('employee_ids', 'in', current_employee_ids) + ('employee_ids', 'in', active_employee_ids), + '|', *log1_domain, *log2_domain ] if (operator == '=' and value) or (operator == '!=' and not value): domain = base_domain elif (operator == '=' and not value) or (operator == '!=' and value): domain = ['!'] + base_domain else: - domain = [] + domain = [('id', '=', False)] + return domain @api.depends('employee_ids', 'soong_state', 'reclaim_state')