diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 394e79de9..6848f0f12 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -540,6 +540,16 @@ class HrAttendance(models.Model): # ]) # if attendance: # attendance.write({'shift_id': slot.shift_id.id}) + def update_attendance(self): + start_time = datetime(2025, 3, 18, 14, 48, 0) + end_time = datetime(2025, 3, 18, 14, 48, 59) + attendance_records = self.env['hr.attendance'].search([ + ('check_in', '>=', start_time), + ('check_in', '<=', end_time) + ]) + if attendance_records: + for attendance_record in attendance_records: + attendance_record.write({'check_in': False}) class card_remind_form(models.Model): _name = 'card.remind.form' diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml index 5fe4568d2..0218d4dac 100644 --- a/yuthon_hr_attendance/views/hr_attendance_views.xml +++ b/yuthon_hr_attendance/views/hr_attendance_views.xml @@ -65,8 +65,6 @@ hr.attendance tree,form,search [('employee_id.user_id', '=', uid)] - 考勤记录 diff --git a/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py b/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py index fae24b29a..250433a8f 100644 --- a/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py +++ b/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py @@ -162,6 +162,7 @@ class HrAttendanceMonthWizard(models.TransientModel): wizard.search_attendance_month() def get_leave_and_overtime_info(self, employee_id): + calendar_leaves = self.env['resource.calendar.leaves'].search([]) leave_types = { '年假': 'annual_leave', '事假': 'unpaid_leave', @@ -204,28 +205,58 @@ class HrAttendanceMonthWizard(models.TransientModel): leave_end = leave.date_to.date() start_in_month = max(leave_start, date_from) end_in_month = min(leave_end, date_to) - # 判断是否跨月 is_cross_month = leave_start.year != leave_end.year or leave_start.month != leave_end.month if is_cross_month: - if leave_start.year == year and leave_start.month == month: - # 请假开始在当前月,如 2 月 16 号开始,2 月取 2 月底减去 16 - days_in_month = (date(year, month + 1, 1) - leave_start).days if month < 12 else (date(year + 1, 1, 1) - leave_start).days - leave_days[leave_type] = days_in_month - elif leave_end.year == year and leave_end.month == month: - # 请假结束在当前月,如 5 月 6 号结束,5 月取 6 天 - days_in_month = (leave_end - date(year, month, 1)).days + 1 - leave_days[leave_type] = days_in_month + if holiday_status_id.type_of_work == '0': + if leave_start.year == year and leave_start.month == month: + # 请假开始在当前月,如 2 月 16 号开始,2 月取 2 月底减去 16 + days_in_month = (date(year, month + 1, 1) - leave_start).days if month < 12 else (date(year + 1, 1, 1) - leave_start).days + leave_days[leave_type] = days_in_month + elif leave_end.year == year and leave_end.month == month: + # 请假结束在当前月,如 5 月 6 号结束,5 月取 6 天 + days_in_month = (leave_end - date(year, month, 1)).days + 1 + leave_days[leave_type] = days_in_month + else: + # 正常情况,计算当前月内的天数 + days_in_month = (end_in_month - start_in_month).days + leave_days[leave_type] = days_in_month else: - # 正常情况,计算当前月内的天数 - days_in_month = (end_in_month - start_in_month).days - leave_days[leave_type] = days_in_month + if leave_start.year == year and leave_start.month == month: + start_date = leave_start + if leave_end.year == year and leave_end.month == month: + end_date = leave_end + else: + end_date = date(year, month + 1, 1) if month < 12 else date(year + 1, 1, 1) + end_date = end_date - datetime.timedelta(days=1) # 取到当月最后一天 + elif leave_end.year == year and leave_end.month == month: + start_date = date(year, month, 1) + end_date = leave_end + else: + start_date = start_in_month + end_date = end_in_month + admin_id = self.env['hr.employee'].search([("name", "=", '李园')]) + leave = self.env['hr.leave'].sudo().create({ + 'employee_id': admin_id.id, + 'holiday_status_id': holiday_status_id.id, + 'request_date_from': start_date, + 'request_date_to': end_date, + 'state': 'confirm', + }) + leave_days[leave_type] = leave.number_of_days + for calendar in calendar_leaves: + shift_days = calendar.shift_replacement_day.split(',') if calendar.shift_replacement_day else [] + for day_str in shift_days: + day = datetime.datetime.strptime(day_str, '%m月%d日') + day = day.replace(year=start_date.year).date() + if start_date <= day <= end_date: + leave_days[leave_type] = leave.number_of_days + 1 + leave.unlink() else: for leave in leave_records: total_days += leave.number_of_days_display leave_days[leave_type] = total_days - employee = self.env['hr.employee'].browse(employee_id) all_overtime_hours = employee.all_overtime_hours attendance_detail = self.env['hr.attendance.month.detail'].search([ diff --git a/yuthon_hr_employee/views/yuthon_hr_employee_views.xml b/yuthon_hr_employee/views/yuthon_hr_employee_views.xml index 40695fe19..b8af66d84 100644 --- a/yuthon_hr_employee/views/yuthon_hr_employee_views.xml +++ b/yuthon_hr_employee/views/yuthon_hr_employee_views.xml @@ -134,25 +134,27 @@ - - - - - - - - - - - - - - - - - -