!11932 考勤确认单台账

Merge pull request !11932 from 李鹏宇/dev_wang
This commit is contained in:
李鹏宇
2026-06-05 11:02:52 +00:00
committed by Gitee
2 changed files with 22 additions and 1 deletions
@@ -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))
@@ -193,7 +193,8 @@
<h1>
<field name="display_date"/>
</h1>
<button name="action_next_month" type="object" string="&#9654;" class="btn btn-secondary ms-3"/>
<field name="can_next_month" invisible="1"/>
<button name="action_next_month" type="object" string="&#9654;" class="btn btn-secondary ms-3" invisible="not can_next_month"/>
</div>
<group col="4">
<group>