From ab9aec8e63a4cc1fbd5f0dc1130a60432effeeba 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, 26 Jan 2026 10:40:08 +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/yuthon_vacation_reports.py | 114 +++++++++++++++++- .../views/yuthon_vacation_reports_views.xml | 3 + .../views/yuthon_salary_active_views.xml | 5 +- 3 files changed, 116 insertions(+), 6 deletions(-) diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 2b43a8424..c00a0d422 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -101,6 +101,96 @@ class YuthonVacationReports(models.Model): tracking=3, default='not_sent') + def update_overtime(self): + today = date.today() + over_line_domain = [ + ('vacation_id', '!=', False), + ('update_type', '=', 'add'), + ('is_void', '=', False) + ] + over_lines = self.env['vacation.over.line'].search(over_line_domain) + + void_lines = self.env['vacation.over.line'] + for line in over_lines: + # 确定判断超期的基准日期:有adjust_date则用adjust_date,否则用valid_date + check_date = line.adjust_date if line.adjust_date else line.valid_date + if check_date and today > check_date: + void_lines |= line + + # 批量标记作废 + if void_lines: + void_lines.write({'is_void': True}) + + for void_line in void_lines: + # 跳过vacation_id为空的情况 + if not void_line.vacation_id: + continue + + main_vacation = void_line.vacation_id + vacation_date = main_vacation.vacation_date + + # 查找vacation_date之后的加班记录中,text='上月继承额度'的行 + inherit_domain = [ + ('vacation_id', '=', main_vacation.id), + ('create_date', '>=', fields.Datetime.to_datetime(vacation_date)), + ('text', '=', '上月继承额度'), + ] + inherit_lines = self.env['vacation.over.line'].search(inherit_domain) + if not inherit_lines: + continue + + deduct_value = void_line.workday or 0.0 + for inherit_line in inherit_lines: + new_workday = inherit_line.workday - deduct_value + inherit_line.write({'workday': new_workday}) + + def update_leave(self): + today = date.today() + leave_line_domain = [ + ('vacation_id', '!=', False), + ('update_type', '=', 'add'), + ('is_void', '=', False) + ] + leave_lines = self.env['vacation.leave.line'].search(leave_line_domain) + + void_lines = self.env['vacation.leave.line'] + for line in leave_lines: + check_date = line.adjust_date if line.adjust_date else line.valid_date + if check_date and today > check_date: + void_lines |= line + + # 2. 批量标记作废 + if void_lines: + void_lines.write({'is_void': True}) + + # 3. 扣减update_lines中「上月继承额度」的workday + for void_line in void_lines: + if not void_line.vacation_id: + continue + + main_vacation = void_line.vacation_id + vacation_date = main_vacation.vacation_date + if not vacation_date: + continue + + # 查找vacation_date之后的年假继承记录(关联update_lines) + inherit_domain = [ + ('vacation_id', '=', main_vacation.id), + ('create_date', '>=', fields.Datetime.to_datetime(vacation_date)), + ('text', '=', '上月继承额度'), + ('is_void', '=', False) + ] + inherit_lines = self.env['vacation.leave.line'].search(inherit_domain) + + if not inherit_lines: + continue + + # 扣减年假workday + deduct_value = void_line.workday or 0.0 + for inherit_line in inherit_lines: + new_workday = inherit_line.workday - deduct_value + inherit_line.write({'workday': new_workday}) + @api.depends('other_fee_ids', 'other_fee_ids.holiday_type', 'other_fee_ids.lines', 'other_fee_ids.is_void', 'other_fee_ids.update_type', 'parenting_line_ids', 'parenting_line_ids.update_date', 'parenting_line_ids.end_date', 'parenting_line_ids.lines') @@ -597,6 +687,18 @@ class YuthonVacationReports(models.Model): 'leave': last_month_record.leave, 'working_overtime': last_month_record.working_overtime, 'medical_fee': last_month_record.medical_fee, + 'previous_year': last_month_record.previous_year, + 'valid_date': last_month_record.valid_date, + 'year_distribution': last_month_record.year_distribution, + 'used_this_year': last_month_record.used_this_year, + 'last_holiday': last_month_record.last_holiday, + 'last_workday': last_month_record.last_workday, + 'valid_date1': last_month_record.valid_date1, + 'year_holiday': last_month_record.year_holiday, + 'year_workday': last_month_record.year_workday, + 'previous_year1': last_month_record.previous_year1, + 'used_this_year1': last_month_record.used_this_year1, + 'remainder_year1': last_month_record.remainder_year1, } rec.write(inherit_vals) if rec.leave: @@ -733,9 +835,9 @@ class YuthonVacationReports(models.Model): ) def _compute_working_overtime(self): for record in self: - total_add1 = 0.0 - total_add2 = 0.0 - total_add = 0.0 + total_add1 = 0.0 # 加班时 + total_add2 = 0.0 # (已用补休) + total_add = 0.0 # (剩余补休) legal_total = 0.0 for line in record.overtime_ids: if line.is_void: @@ -750,8 +852,10 @@ class YuthonVacationReports(models.Model): if line.workflow_record_id and line.update_type == 'add' and line.overtime_methods == 'leave': total_add1 += line_total + if line.workflow_record_id and line.update_type == 'reduce': total_add2 += line_total + adjust_holiday_days = 0.0 for other_line in record.other_fee_ids: if other_line.holiday_type and other_line.holiday_type.name == '调休': @@ -856,6 +960,7 @@ class YuthonVacationReports(models.Model): continue self.env['vacation.leave.line'].create({ 'vacation_id': report.id, + 'valid_date': report.valid_date, 'employee_id': report.employee_id.id, 'update_type': 'add', 'update_date': fields.Date.today(), @@ -878,6 +983,7 @@ class YuthonVacationReports(models.Model): self.env['vacation.over.line'].create({ 'vacation_id': report.id, 'employee_id': report.employee_id.id, + 'valid_date': report.valid_date1, 'update_type': 'add', 'update_date': fields.Date.today(), 'workday': number_of_hours_display, @@ -1026,7 +1132,7 @@ class VacationOverline(models.Model): remaining_quantity = fields.Float(string='剩余数', compute="_compute_remaining_quantity", store=True) def open_record1(self): - tree_id = self.env.ref("yuthon_vacation_reports.view_yuthon_vacation_overtime_tree").id + tree_id = self.env.ref("yuthon_hr_attendance.view_yuthon_vacation_overtime_tree").id return { 'type': 'ir.actions.act_window', 'name': 'Overtime Record', diff --git a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml index 9adc5a914..5686f4529 100644 --- a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml +++ b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml @@ -36,6 +36,9 @@ yuthon.vacation.reports +
+
diff --git a/yuthon_salary/views/yuthon_salary_active_views.xml b/yuthon_salary/views/yuthon_salary_active_views.xml index 84482cc1b..e1560cb0a 100644 --- a/yuthon_salary/views/yuthon_salary_active_views.xml +++ b/yuthon_salary/views/yuthon_salary_active_views.xml @@ -65,7 +65,7 @@ - +
@@ -87,7 +87,7 @@ yuthon.salary.active -