diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 2859be671..8d3d35e26 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -54,8 +54,8 @@ class YuthonVacationReports(models.Model): internship_days = fields.Float(string='实习天数', group_operator=None, compute='compute_attendance_fields') test_days = fields.Float(string='试用天数', group_operator=None) - should_attendance = fields.Integer(string="应到", store=True, group_operator=None, compute='compute_attendance_fields') - actual_attendance = fields.Integer(string="实到", compute='compute_attendance_fields', store=True,group_operator=None) + should_attendance = fields.Float(string="应到", store=True, group_operator=None, compute='compute_attendance_fields') + actual_attendance = fields.Float(string="实到", compute='compute_attendance_fields', store=True,group_operator=None) is_late_card = fields.Integer(string="迟到", compute='compute_attendance_fields', store=True, group_operator=None) is_early_card = fields.Integer(string="早退", compute='compute_attendance_fields', store=True, group_operator=None) @@ -170,9 +170,9 @@ class YuthonVacationReports(models.Model): leave_days = 0 internship_days = 0 # 实习期天数 is_abnormal = 0 - actual_attendance = 0 - approved_dates = set() # 储存审批记录 - workflow_dates = set() # 储存审处于工作流中的记录 + actual_attendance = 0 # 实到天数 = 应到天数 - 请假总天数 + total_leave_days = 0 # 请假工作流总天数(含小时折算) + if rec.employee_id and rec.vacation_date: year = rec.vacation_date.year month = rec.vacation_date.month @@ -194,33 +194,6 @@ class YuthonVacationReports(models.Model): ('employee_id', '=', rec.employee_id.id), ("current_data", '=', current_date) ]) - has_approved = False - has_leave_workflow = False - - for att in attendances: - # 判断是否为审批通过且无工作流的记录 - if att.is_approval and not att.workflow_id: - has_approved = True - - # 判断是否为工作流名称为"请假"的记录 - if att.workflow_id and att.workflow_id.workflow_id.name == '请假': - has_leave_workflow = True - - # 记录符合条件的日期 - if has_approved: - approved_dates.add(current_date) - if has_leave_workflow: - workflow_dates.add(current_date) - - if attendances: - valid_attendances = [ - att for att in attendances - if (att.check_in or att.check_out) - and att.workflow_id.workflow_id.name != '请假' - ] - if valid_attendances: - actual_attendance += 1 - for att in attendances: if att.is_late_card: is_late += 1 @@ -233,8 +206,20 @@ class YuthonVacationReports(models.Model): if att.is_abnormal: is_abnormal += 1 - total_adjust_dates = approved_dates.union(workflow_dates) - leave_days = leave_days - len(total_adjust_dates) + for att in attendances: + if att.workflow_id and att.workflow_id.workflow_id.name == '请假': + res_model = att.workflow_id.res_model + res_id = att.workflow_id.res_id + if res_model and res_id: + related_model = self.env[res_model].sudo().browse(res_id) + if related_model.exists(): + if related_model.days: + total_leave_days += float(related_model.days) + # 小时数折算为天数(1天=8小时) + elif related_model.hours: + total_leave_days += float(related_model.hours) / 8 + + actual_attendance = round(max(0, leave_days - total_leave_days), 1) rec.internship_days = internship_days rec.should_attendance = leave_days