diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 9c50b91bf..0b47fefbb 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -927,8 +927,8 @@ class HolidaysRequestBatch(models.Model): overtime_days = reports_id.working_overtime if total_annual_leave_days > leave_days: raise UserError('年假天数额度不足,无法请假') - # if total_compensatory_leave_days > overtime_days: - # raise UserError('补休天数额度不足,无法请假') + if total_compensatory_leave_days > overtime_days: + raise UserError('补休天数额度不足,无法请假') @api.onchange('leave_ids', 'hour_leave_ids', 'employee_id') diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index bb2e943a7..9aa6da9ae 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -259,7 +259,6 @@ class HrAttendance(models.Model): # datetime=format_datetime(self.env, last_attendance_before_check_out.check_in, dt_format=False) # )) - #考勤异常提醒 def attendance_abnormal_remind(self): today = date.today() current_year = today.year @@ -271,11 +270,12 @@ class HrAttendance(models.Model): last_month = current_month - 1 last_month_year = current_year last_month_first_day = date(last_month_year, last_month, 1) - yesterday = today - timedelta(days=1) + last_month_last_day = date(current_year, current_month, 1) - timedelta(days=1) + yesterday = today - timedelta(days=1) # 昨天 attendance_records = self.env['hr.attendance'].search([ - ('current_data', '>=', last_month_first_day), # 上个月1号及以后 - ('current_data', '<=', yesterday), # 昨天及以前(跳过今天) - ('shift_name', '!=', '休息') + ('current_data', '>=', last_month_first_day), + ('current_data', '<=', yesterday), + ('shift_name', '!=', '休息'), ]) employee_abnormal = {} for rec in attendance_records: @@ -285,47 +285,34 @@ class HrAttendance(models.Model): if emp_id in resource_user_ids: continue if emp_id not in employee_abnormal: - employee_abnormal[emp_id] = {'abnormal_list': [], 'employee': emp} - - # 提取基础信息:日期(月-日)、班次 - att_date = rec.current_data - date_str = att_date.strftime('%m-%d') - shift_name = rec.shift_name - - # 判断异常类型(优先级:缺卡 > 迟到/早退) - abnormal_desc = "" - # 判断缺卡类型 - if not rec.check_in and not rec.check_out: - abnormal_desc = "缺上班卡、缺下班卡" - elif not rec.check_in: - abnormal_desc = "缺上班卡" - elif not rec.check_out: - abnormal_desc = "缺下班卡" - # 无缺卡时,判断迟到/早退 - else: - abnormal_list = [] - if rec.is_late_card: - abnormal_list.append("迟到") - if rec.is_early_card: - abnormal_list.append("早退") - if abnormal_list: - abnormal_desc = '、'.join(abnormal_list) - - if abnormal_desc: - single_abnormal = f"{date_str} {shift_name} {abnormal_desc}" - employee_abnormal[emp_id]['abnormal_list'].append(single_abnormal) + employee_abnormal[emp_id] = { + 'employee': emp, + 'last_month_abnormal': [], # 上月异常列表 + 'current_month_abnormal': [] # 本月异常列表 + } + if rec.is_abnormal: + att_date = rec.current_data + date_str = att_date.strftime('%m-%d') + shift_name = rec.shift_name + single_abnormal = f"{date_str} {shift_name}" + if att_date <= last_month_last_day: + employee_abnormal[emp_id]['last_month_abnormal'].append(single_abnormal) + else: + employee_abnormal[emp_id]['current_month_abnormal'].append(single_abnormal) + # 4. 统一处理每个员工的提醒(合并上月+本月异常) for emp_id, data in employee_abnormal.items(): emp = data['employee'] - abnormal_list = data['abnormal_list'] - if not abnormal_list: - continue - # abnormal_str = '、'.join(abnormal_list) - # reminder_msg = f"{abnormal_str},请尽快处理。" - # menu_id = self.env['ir.ui.menu'].search([('name', '=', '我的考勤')]) - # target_url = f'https://oa.thtzjt.com/web=#action=2465&model=hr.attendance&view_type=list&cids=2-1-3-4&menu_id={menu_id}' - # url = self.sudo().env["wecom.apps"].generate_oauth_login_url(target_url, emp.user_id.id) + last_month_abnormal = data['last_month_abnormal'] + current_month_abnormal = data['current_month_abnormal'] + vacation_report = self.env['yuthon.vacation.reports'].search([ + ('employee_id', '=', emp_id), + ('vacation_date', '=', last_month_first_day), + ], limit=1) + # 无需要提醒的异常则跳过:上月异常已确认 且 本月无异常 + if (not last_month_abnormal or (vacation_report and vacation_report.vacation_state == 'confirmed')) and not current_month_abnormal: + continue url = f'https://phone.thtzjt.com/phone/AttendanceSummary/{fields.date.today().year}/{fields.date.today().month}/{emp.user_id.id}' self.sudo().env["wecom.apps"].sync_send_message_textcard(category='att_ok', user_id=emp.wecom_userid,