From cce2add52eb13a07c3ce06c80b3de4fb9c67bb6b 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: Tue, 18 Aug 2026 19:04:33 +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 | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 24c9b054c..add75d2d9 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -70,7 +70,7 @@ class YuthonVacationReports(models.Model): used_this_year1 = fields.Float(string="本年已休d", digits=(16, 3)) company_id = fields.Many2one(related="employee_id.company_id", string="公司", store=True) - late_allowed = fields.Float(related="employee_id.late_allowed", string="允许迟到次数") + late_allowed = fields.Float(string="允许迟到次数", compute="_compute_late_allowed_fields", store=False) leave_ids = fields.One2many('vacation.leave.line', 'vacation_id', string='年假明细') overtime_ids = fields.One2many('vacation.over.line', 'vacation_id', string='加班明细') # 加班明细合计字段 @@ -249,6 +249,28 @@ class YuthonVacationReports(models.Model): record.duty = max(total_duty_count - duty_off_count, 0) @api.depends('vacation_date', 'employee_id') + @api.depends('employee_id', 'vacation_date') + def _compute_late_allowed_fields(self): + for record in self: + # 每月发放:天河物管员工 3 次允许迟到次数,其余公司 0 + if record.employee_id and record.employee_id.company_id.name == "天河物管": + grant = 3 + else: + grant = 0 + # 当月已使用的宽容迟到次数(is_late_allowed=True 的考勤记录数) + used = 0 + if record.employee_id and record.vacation_date: + month_start = record.vacation_date.replace(day=1) + month_end = month_start + relativedelta(months=1) + used = self.env['hr.attendance'].search_count([ + ('employee_id', '=', record.employee_id.id), + ('current_data', '>=', month_start), + ('current_data', '<', month_end), + ('is_late_allowed', '=', True), + ]) + # 允许迟到次数(剩余)= 发放 - 已用 + record.late_allowed = max(0, grant - used) + def _compute_number_card(self): for record in self: count = 0