From 66e7a8293f5029e7d6bc8e7f9a5773df693f94ae Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Sun, 25 May 2025 20:33:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/soong_workflow_record.xml | 2 +- .../wizard/soong_workflow_comment_wizard.py | 8 ++--- yuthon_holiday/models/inherit_hr_leave.py | 36 +++++++++++++------ yuthon_trade/views/yuthon_trade_premium.xml | 9 +++-- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/soong_workflow/views/soong_workflow_record.xml b/soong_workflow/views/soong_workflow_record.xml index f7d0cbb11..5d9e00fd4 100644 --- a/soong_workflow/views/soong_workflow_record.xml +++ b/soong_workflow/views/soong_workflow_record.xml @@ -112,7 +112,7 @@ ir.actions.act_window soong.workflow.record tree,kanban,search - [('users_ids', 'in', [uid])] + [('employee_ids.user_id', '=', uid)] diff --git a/soong_workflow/wizard/soong_workflow_comment_wizard.py b/soong_workflow/wizard/soong_workflow_comment_wizard.py index d2a2080ae..49c700373 100644 --- a/soong_workflow/wizard/soong_workflow_comment_wizard.py +++ b/soong_workflow/wizard/soong_workflow_comment_wizard.py @@ -124,14 +124,14 @@ class SoongWorkflowCommentWizard(models.TransientModel): next_is_automatic = workflow_id.node_ids.search([('name', '=', self.trans_link_id.name), ('workflow_id', '=', workflow_id.id)]).button_ids[0].is_automatic employee_user_role_ids = employee_user_role_id = False if link_users_id: - employee_user_role_ids = self.env['hr.employee'].search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 自动匹配 - employee_user_role_id = self.env['hr.employee'].search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), + employee_user_role_ids = self.env['hr.employee'].sudo().search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 自动匹配 + employee_user_role_id = self.env['hr.employee'].sudo().search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), '|', ('department_id', '=', record_id.department_id.id), ('department_ids', 'in', record_id.department_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 不自动匹配 elif link_users_group_ids: # 不自动匹配 - employee_user_role_ids = self.env['hr.employee'].search(['|', ('user_role_id', 'in', link_users_group_ids.user_role_ids.ids), ('user_role_ids', 'in', link_users_group_ids.user_role_ids.ids)]) + employee_user_role_ids = self.env['hr.employee'].sudo().search(['|', ('user_role_id', 'in', link_users_group_ids.user_role_ids.ids), ('user_role_ids', 'in', link_users_group_ids.user_role_ids.ids)]) # 自动匹配 - employee_user_role_id = self.env['hr.employee'].search([('id', 'in', employee_user_role_ids.ids), + employee_user_role_id = self.env['hr.employee'].sudo().search([('id', 'in', employee_user_role_ids.ids), # ("user_role_ids", "in", employee_user_role_ids.id), '|', ('department_id', '=', record_id.department_id.id), ('department_ids', 'in', record_id.department_id.id), diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 44f018c15..9fad67f3a 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -376,24 +376,40 @@ class HolidaysRequestBatch(models.Model): self.leave_ids.action_validate() self.hour_leave_ids.action_validate() - @api.constrains('hour_leave_ids') - def _check_hour_leave_hours(self): - """检查小时请假记录的小时数是否为0""" - number_hours = 0 + @api.constrains('is_day', 'is_hour', 'leave_ids', 'hour_leave_ids') + def _check_leave_type_and_details(self): + """检查请假类型和明细行是否符合要求""" for record in self: + # 验证 is_day 和 is_hour 不能同时为空 + if not record.is_day and not record.is_hour: + raise ValidationError(_("请选择按天请假或按小时请假!")) + # 验证 leave_ids 和 hour_leave_ids 不能同时为空 + if not record.leave_ids and not record.hour_leave_ids: + raise ValidationError(_("请至少添加一条按天或按小时的请假记录!")) + # 验证按天请假时必须选择按天请假 + if record.leave_ids and not record.is_day: + raise ValidationError(_("添加了按天请假记录,必须选择'按天请假'选项!")) + # 验证按小时请假时必须选择按小时请假 + if record.hour_leave_ids and not record.is_hour: + raise ValidationError(_("添加了按小时请假记录,必须选择'按小时请假'选项!")) + # 原有的小时数验证逻辑(仅在按小时请假时有小时记录时执行) if record.hour_leave_ids and not record.leave_ids: + number_hours = 0 for line in record.hour_leave_ids: if line.request_date_from and line.request_hour_to: # 使用正则表达式提取小时数 match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '') if match and float(match.group(1)) == 0: raise ValidationError(_("请假小时数不能为0!")) - if record.company_id.name == '天河物管': - match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '') - number_hours += float(match.group(1)) - valid_hours = [2, 4, 6, 8] - if number_hours not in valid_hours: - raise ValidationError("休假时长必须为 2、4、6 或 8 小时才可以保存!") + if record.company_id.name == '天河物管': + match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '') + if match: + number_hours += float(match.group(1)) + # 天河物管的总小时数验证 + if record.company_id.name == '天河物管' and number_hours: + valid_hours = [2, 4, 6, 8] + if number_hours not in valid_hours: + raise ValidationError(_("休假时长必须为 2、4、6 或 8 小时才可以保存!")) @api.onchange('leave_ids', 'hour_leave_ids', 'employee_id') def _onchange_leave_dates(self): diff --git a/yuthon_trade/views/yuthon_trade_premium.xml b/yuthon_trade/views/yuthon_trade_premium.xml index 2069d712e..996aa4572 100644 --- a/yuthon_trade/views/yuthon_trade_premium.xml +++ b/yuthon_trade/views/yuthon_trade_premium.xml @@ -49,8 +49,13 @@ - - +