From fd3d8069a804bbec6fefa33bd6470012c829b1cc 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: Mon, 9 Feb 2026 21:24:30 +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 --- .../models/overtime_active_line.py | 9 +++++ .../models/remove_holiday_approval.py | 40 ++++++++++++++++++- .../models/vacation_meal_active.py | 8 ++++ .../models/vacation_overtime_active.py | 8 ++++ .../models/yuthon_vacation_reports.py | 6 +-- .../src/xml/button_meal_active_export.xml | 2 +- .../views/overtime_active_line_views.xml | 3 ++ .../views/vacation_meal_active_views.xml | 1 + .../views/vacation_overtime_active_views.xml | 1 + 9 files changed, 73 insertions(+), 5 deletions(-) diff --git a/yuthon_hr_attendance/models/overtime_active_line.py b/yuthon_hr_attendance/models/overtime_active_line.py index 3b7066653..b5f50c4f9 100644 --- a/yuthon_hr_attendance/models/overtime_active_line.py +++ b/yuthon_hr_attendance/models/overtime_active_line.py @@ -30,6 +30,15 @@ class OvertimeActiveLine(models.Model): validity = fields.Char(string="有效期") is_void = fields.Boolean(string="作废", default=False) + + def all_unlink(self): + active_ids = self.env["overtime.active.line"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for record in active_ids: + if not record.is_void: + raise UserError("只有作废的加班记录才能删除,请先撤销") + record.unlink() + def action_export_overtime_active_excel(self): """导出加班归档明细 Excel 报表 - 打开向导选择日期""" # 获取当前选中的记录 ID diff --git a/yuthon_hr_attendance/models/remove_holiday_approval.py b/yuthon_hr_attendance/models/remove_holiday_approval.py index 34aa7d6e3..3969f8ef1 100644 --- a/yuthon_hr_attendance/models/remove_holiday_approval.py +++ b/yuthon_hr_attendance/models/remove_holiday_approval.py @@ -33,6 +33,11 @@ class RemoveHolidayApprovals(models.Model): name_title = fields.Char(default=_get_default_name_title) self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])]) + @api.onchange('workflow_id1', 'users_id') + def _onchange_name(self): + if self.workflow_id1 and self.users_id: + self.name = f"销假单-{self.workflow_id1.name}" + @api.onchange('is_issues') def _onchange_is_issues(self): if self.is_issues: @@ -49,6 +54,12 @@ class RemoveHolidayApprovals(models.Model): }) def remove_holiday_approval(self): + """ + 核心方法: + 1. 标记假期明细行(leave/over/meal等)为作废 + 2. 根据is_day/is_hour修改对应请假批次状态为refuse + """ + # 步骤1:定义需要作废的明细模型列表 detail_models = [ 'vacation.leave.line', 'vacation.over.line', @@ -60,12 +71,39 @@ class RemoveHolidayApprovals(models.Model): for model_name in detail_models: detail_model = self.env[model_name] domain = [ - ('workflow_id', '=', self.workflow_id1), + ('workflow_record_id', '=', self.workflow_id1.id), ('is_void', '=', False) ] matching_detail_lines = detail_model.search(domain) if matching_detail_lines: matching_detail_lines.write({'is_void': True}) + matching_detail_lines.vacation_id.update_line() + + record = self.env[self.workflow_id1.res_model].search([('id', '=', self.workflow_id1.res_id)]) + if record: + leave_records = self.env['hr.leave'] + if record.is_day and record.leave_ids: + leave_records += record.leave_ids + if record.is_hour and record.hour_leave_ids: + leave_records += record.hour_leave_ids + + if leave_records: + leave_records.sudo().write({'state': 'refuse'}) + for leave in leave_records: + if not leave.date_from or not leave.date_to or not leave.employee_id: + continue + start_date = leave.date_from.date() + end_date = leave.date_to.date() + employee = leave.employee_id + attend_records = self.env['hr.attendance'].sudo().search([ + ('employee_id', '=', employee.id), + ('current_data', '>=', start_date), + ('current_data', '<=', end_date) + ]) + if attend_records: + attend_records.compute_attend() + attend_records.workflow_id = False + attend_records.is_workflow = False @api.depends('date_start', 'date_end') def _compute_duration(self): diff --git a/yuthon_hr_attendance/models/vacation_meal_active.py b/yuthon_hr_attendance/models/vacation_meal_active.py index b904ae114..f7bbb144b 100644 --- a/yuthon_hr_attendance/models/vacation_meal_active.py +++ b/yuthon_hr_attendance/models/vacation_meal_active.py @@ -30,6 +30,14 @@ class VacationMealActive(models.Model): default='pending', ) + def all_unlink(self): + active_ids = self.env["vacation.meal.active"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for record in active_ids: + if not record.select_revoke == 'done': + raise UserError("只有撤销的误餐记录才能删除,请先撤销") + record.unlink() + def revoke(self): self.ensure_one() self.select_revoke = 'done' diff --git a/yuthon_hr_attendance/models/vacation_overtime_active.py b/yuthon_hr_attendance/models/vacation_overtime_active.py index d4d48c2c6..e86fb1687 100644 --- a/yuthon_hr_attendance/models/vacation_overtime_active.py +++ b/yuthon_hr_attendance/models/vacation_overtime_active.py @@ -31,6 +31,14 @@ class VacationOvertimeActive(models.Model): remaining_quantity = fields.Float(string="剩余数") select_revoke = fields.Selection([('to_do', '待撤销'), ('done', '已撤销')], string='状态') + def all_unlink(self): + active_ids = self.env["vacation.overtime.active"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for record in active_ids: + if not record.select_revoke == 'done': + raise UserError("只有撤销的加班记录才能删除,请先撤销") + record.unlink() + def revoke(self): self.ensure_one() self.select_revoke = 'done' diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 767a7da81..5a615b8f3 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -190,7 +190,7 @@ class YuthonVacationReports(models.Model): # ========== 第一步:处理年假逻辑 ========== for rec in self: valid_leave_lines = rec.leave_ids.filtered( - lambda l: l.workflow_record_id and l.update_type == 'reduce' + lambda l: l.workflow_record_id and l.update_type == 'reduce' and l.is_void != True ) total_leave_deduct = sum(line.update_lines for line in valid_leave_lines if line.update_lines > 0)/8 @@ -212,7 +212,7 @@ class YuthonVacationReports(models.Model): # ========== 第二步:处理补休逻辑 ========== for rec in self: reduce_overtime_lines = rec.overtime_ids.filtered( - lambda o: o.update_type == 'reduce' and (o.workflow_record_id or o.overtime_methods == 'fee') + lambda o: o.update_type == 'reduce' and (o.workflow_record_id or o.overtime_methods == 'fee') and o.is_void != True ) # 计算补休扣减总天数 total_overtime_deduct = sum( @@ -237,7 +237,7 @@ class YuthonVacationReports(models.Model): rec.used_this_year1 += deduct_from_current1 # 累加到本年已休 remaining_overtime_deduct -= deduct_from_current1 - add_overtime_lines = rec.overtime_ids.filtered(lambda o: o.workflow_record_id and o.update_type == 'add') + add_overtime_lines = rec.overtime_ids.filtered(lambda o: o.workflow_record_id and o.update_type == 'add' and o.is_void != True) # 计算补休新增总天数 workday_overtime_add = sum((line.workday or 0) for line in add_overtime_lines) / 8 holidays_overtime_add = sum((line.public_holidays or 0) for line in add_overtime_lines) / 8 diff --git a/yuthon_hr_attendance/static/src/xml/button_meal_active_export.xml b/yuthon_hr_attendance/static/src/xml/button_meal_active_export.xml index a8107c4c4..eb96ef58b 100644 --- a/yuthon_hr_attendance/static/src/xml/button_meal_active_export.xml +++ b/yuthon_hr_attendance/static/src/xml/button_meal_active_export.xml @@ -3,7 +3,7 @@ diff --git a/yuthon_hr_attendance/views/overtime_active_line_views.xml b/yuthon_hr_attendance/views/overtime_active_line_views.xml index a6e74e2d3..56de248d2 100644 --- a/yuthon_hr_attendance/views/overtime_active_line_views.xml +++ b/yuthon_hr_attendance/views/overtime_active_line_views.xml @@ -5,6 +5,9 @@ overtime.active.line +
+
diff --git a/yuthon_hr_attendance/views/vacation_meal_active_views.xml b/yuthon_hr_attendance/views/vacation_meal_active_views.xml index f70f17cd3..2da3e047b 100644 --- a/yuthon_hr_attendance/views/vacation_meal_active_views.xml +++ b/yuthon_hr_attendance/views/vacation_meal_active_views.xml @@ -7,6 +7,7 @@
diff --git a/yuthon_hr_attendance/views/vacation_overtime_active_views.xml b/yuthon_hr_attendance/views/vacation_overtime_active_views.xml index 206eadee0..308c591ba 100644 --- a/yuthon_hr_attendance/views/vacation_overtime_active_views.xml +++ b/yuthon_hr_attendance/views/vacation_overtime_active_views.xml @@ -7,6 +7,7 @@