From 8cdca2e7ee5868a092e4ad8465fb1f47774f66c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Wed, 14 Jan 2026 14:26:24 +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 --- yuthon_holiday/models/inherit_hr_leave.py | 20 +++++++++++++++++++ .../models/yuthon_onboard_approval.py | 2 +- .../views/yuthon_message_login_views.xml | 2 +- .../views/yuthon_onboard_approval_views.xml | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 3b92ab0d7..a8d173e67 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -67,6 +67,26 @@ class HrLeave(models.Model): else: self.request_hour_to = False + @api.ondelete(at_uninstall=False) + def _unlink_if_correct_states(self): + """重写删除校验:先将请假单改为拒绝状态,再执行原生校验/删除""" + to_cancel_leaves = self.filtered(lambda r: r.state != 'cancel') + if to_cancel_leaves: + to_cancel_leaves.write({ + 'state': 'cancel', + 'notes': _('%s:删除前自动标记为拒绝') % fields.Datetime.now() + }) + error_message = _('You cannot delete a time off which is in %s state') + state_description_values = {elem[0]: elem[1] for elem in self._fields['state']._description_selection(self.env)} + if not self.user_has_groups('hr_holidays.group_hr_holidays_user'): + for hol in self: + if hol.state not in ['draft', 'confirm', 'validate1', 'cancel']: + raise UserError(error_message % state_description_values.get(hol.state)) + if hol.sudo().employee_ids and not hol.employee_id: + raise UserError(_('You cannot delete a time off assigned to several employees')) + else: + for holiday in self.filtered(lambda holiday: holiday.state not in ['draft', 'cancel', 'confirm']): + raise UserError(error_message % (state_description_values.get(holiday.state),)) def action_leave_wizard(self): return { diff --git a/yuthon_hr_employee_approval/models/yuthon_onboard_approval.py b/yuthon_hr_employee_approval/models/yuthon_onboard_approval.py index 713318b19..7f3a497e1 100644 --- a/yuthon_hr_employee_approval/models/yuthon_onboard_approval.py +++ b/yuthon_hr_employee_approval/models/yuthon_onboard_approval.py @@ -222,7 +222,7 @@ class YuthonOnboardApproval(models.Model): vacation_date = self.duration_employment.replace(day=1) self.env['yuthon.vacation.reports'].search([('employee_id', '=', employee_id.id), ('vacation_date', '=', vacation_date)]) if not vacation_date: - self.env['yuthon.vacation.reports'].create({ + self.env['yuthon.vacation.reports'].sudo().create({ 'employee_id': employee_id.id, 'vacation_date': vacation_date, }) diff --git a/yuthon_hr_employee_approval/views/yuthon_message_login_views.xml b/yuthon_hr_employee_approval/views/yuthon_message_login_views.xml index f7de9a13a..96a3db65d 100644 --- a/yuthon_hr_employee_approval/views/yuthon_message_login_views.xml +++ b/yuthon_hr_employee_approval/views/yuthon_message_login_views.xml @@ -86,7 +86,7 @@ - + diff --git a/yuthon_hr_employee_approval/views/yuthon_onboard_approval_views.xml b/yuthon_hr_employee_approval/views/yuthon_onboard_approval_views.xml index 5af48dd76..f01a45df7 100644 --- a/yuthon_hr_employee_approval/views/yuthon_onboard_approval_views.xml +++ b/yuthon_hr_employee_approval/views/yuthon_onboard_approval_views.xml @@ -95,7 +95,7 @@ - +