diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index a27f8bfef..03b6e37c5 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -73,6 +73,7 @@ class YuthonVacationReports(models.Model): other_fee_ids = fields.One2many('vacation.other.line', 'vacation_id', string='其他明细') duty_ids = fields.One2many('duty.adjustment.schedule', 'vacation_id', string='值班调休明细', compute='_compute_duty_ids') vacation_date = fields.Date(string='日期', default=lambda self: fields.Date.today().replace(day=1)) + can_next_month = fields.Boolean(string='可切换下月', compute='_compute_can_next_month') show_date = fields.Date(string='日期', compute='_compute_display_date', store=True) display_date = fields.Char(string='日期', compute='_compute_display_date') done_leave = fields.Float(string='年假', compute='_compute_leave', store=True, digits=(16, 3), group_operator=None) @@ -701,6 +702,13 @@ class YuthonVacationReports(models.Model): f"已存在假期额度记录,不能重复创建!" ) + @api.depends('vacation_date') + def _compute_can_next_month(self): + today = fields.Date.today() + for record in self: + next_month_date = (record.vacation_date + relativedelta(months=1)).replace(day=1) + record.can_next_month = next_month_date <= today + def action_prev_month(self): """跳转到上一个月的假期记录""" self.ensure_one() @@ -723,6 +731,8 @@ class YuthonVacationReports(models.Model): def action_next_month(self): """跳转到下一个月的假期记录""" self.ensure_one() + if not self.can_next_month: + raise UserError('当前时间尚未进入下个月,无法切换!') next_date = (self.vacation_date + relativedelta(months=1)).replace(day=1) next_record = self.search([ ('employee_id', '=', self.employee_id.id), @@ -1758,6 +1768,16 @@ class YuthonVacationReports(models.Model): 'default_name': '补休增加', }} + def cron_auto_recompute_vacation(self): + """定时任务:每月1号自动批量重新计算上月假期额度""" + today = fields.Date.today() + last_month_first = today.replace(day=1) - timedelta(days=1) + last_month_first = last_month_first.replace(day=1) + + records = self.search([('vacation_date', '=', last_month_first)]) + if records: + records.with_context(active_ids=records.ids).batch_compute_leave_and_overtime() + def batch_compute_leave_and_overtime(self): records = self.env["yuthon.vacation.reports"].browse( self._context.get('active_ids', self._context.get('active_id', self.ids)) diff --git a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml index bdb417fdb..bc8158e8c 100644 --- a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml +++ b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml @@ -193,7 +193,8 @@