diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index b573e2c36..b5099ac09 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -669,6 +669,44 @@ class YuthonVacationReports(models.Model): f"已存在假期额度记录,不能重复创建!" ) + def action_prev_month(self): + """跳转到上一个月的假期记录""" + self.ensure_one() + prev_date = (self.vacation_date - relativedelta(months=1)).replace(day=1) + prev_record = self.search([ + ('employee_id', '=', self.employee_id.id), + ('vacation_date', '=', prev_date), + ], limit=1) + if not prev_record: + raise UserError('上一个月没有对应的假期记录') + action = self.env['ir.actions.actions']._for_xml_id('yuthon_hr_attendance.view_yuthon_vacation_reports_action') + action.update({ + 'res_id': prev_record.id, + 'views': [(False, 'form')], + 'view_mode': 'form', + 'target': 'current', + }) + return action + + def action_next_month(self): + """跳转到下一个月的假期记录""" + self.ensure_one() + next_date = (self.vacation_date + relativedelta(months=1)).replace(day=1) + next_record = self.search([ + ('employee_id', '=', self.employee_id.id), + ('vacation_date', '=', next_date), + ], limit=1) + if not next_record: + raise UserError('下一个月没有对应的假期记录') + action = self.env['ir.actions.actions']._for_xml_id('yuthon_hr_attendance.view_yuthon_vacation_reports_action') + action.update({ + 'res_id': next_record.id, + 'views': [(False, 'form')], + 'view_mode': 'form', + 'target': 'current', + }) + return action + def action_open(self): self.ensure_one() target_date = self.vacation_date.replace(day=1) diff --git a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml index d43a29a1c..231128d5f 100644 --- a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml +++ b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml @@ -180,10 +180,12 @@ -
-

+
+