From 3bba3e2d056efc323a4968fe6059f1c11eaa9d88 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: Mon, 22 Sep 2025 10:57:35 +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 --- yuthon_hr_attendance/models/hr_attendance.py | 93 ++++++++++++++----- .../models/yuthon_vacation_reports.py | 1 - .../views/yuthon_vacation_reports_views.xml | 5 +- 3 files changed, 73 insertions(+), 26 deletions(-) diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 99004f5e2..0a7281980 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -229,20 +229,32 @@ class HrAttendance(models.Model): absenteeism_card += 1 if has_abnormal: url = f"https://oa.thtzjt.com/webh5#/clock_in_staticstis?user_id={employee.user_id.id}" - self.sudo().env["wecom.apps"].sync_send_message_textcard(category='att', user_id=employee.wecom_userid, title="打卡异常提醒", - description="本月迟到: {}\n本月缺卡: {}\n本月早退: {}\n本月异常:{}\n 本月旷工: {}\n" - .format(is_late_card, is_no_card, is_early_card, is_abnormal, absenteeism_card), - url=url, btntxt="详细信息") - base_url = self.env['ir.config parameter'].sudo().get_param('web.base.url') - self.env['card.remind.form'].create({ - 'name': employee.name, - 'start_time': current_time, - 'shift': '行政班次', - 'department': employee.department_id.name, - 'remarks': f"域名: {base_url}" - }) - logging.info(f"执行时间为{current_time}") - logging.info(f"打卡异常提醒发送成功,员工:{employee.name},本月迟到: {is_late_card},本月缺卡: {is_no_card},本月早退: {is_early_card},本月异常:{is_abnormal},本月旷工: {absenteeism_card}") + try: + self.sudo().env["wecom.apps"].sync_send_message_textcard( + category='att', + user_id=employee.wecom_userid, + title="打卡异常提醒", + description="本月迟到: {}\n本月缺卡: {}\n本月早退: {}\n本月异常:{}\n 本月旷工: {}\n" + .format(is_late_card, is_no_card, is_early_card, is_abnormal, absenteeism_card), + url=url, + btntxt="详细信息" + ) + base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + self.env['card.remind.form'].create({ + 'name': employee.name, + 'start_time': current_time, + 'shift': '行政班次', + 'department': employee.department_id.name, + 'remarks': f"域名: {base_url}" + }) + self._create_message_log(employee, '3', url) + + # 记录成功日志 + _logger.info(f"执行时间为{current_time}") + _logger.info( + f"打卡异常提醒发送成功,员工:{employee.name},本月迟到: {is_late_card},本月缺卡: {is_no_card},本月早退: {is_early_card},本月异常:{is_abnormal},本月旷工: {absenteeism_card}") + except Exception as e: + _logger.error(f"打卡异常提醒发送失败,员工:{employee.name},错误信息:{str(e)}") def missing_card_judgment(self): today = fields.Date.today() @@ -967,22 +979,57 @@ class HrAttendance(models.Model): 'department': user.department_id.name, }) self.card_duty_remind(user.resource_id.employee_id) + def _create_message_log(self, employee_id, message_type, url): + """创建消息提醒日志记录""" + today = fields.Date.today() + first_day = today.replace(day=1) + + vacation = self.env['yuthon.vacation.reports'].search([ + ('employee_id', '=', employee_id.id), + ('vacation_date', '=', first_day) + ], limit=1) + if vacation: + self.env['attendance.message.log'].create({ + 'vacation_id': vacation.id, + 'employee_id': employee_id.id, + 'update_date': fields.Datetime.now(), + 'message_type': message_type, + 'message_url': url, + }) + def card_in_comment(self, employee_id, planning_name): data = f"您的班次是{planning_name},还有10分钟上班,记得打卡" url = '#小程序://天投云/XttsPpKg3MEpY7h' - self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id=employee_id.wecom_userid, - description=data, - title="打卡提醒", - url=url, btntxt="详细信息") - + try: + self.sudo().env["wecom.apps"].sync_send_message( + category='att', + user_id=employee_id.wecom_userid, + description=data, + title="打卡提醒", + url=url, + btntxt="详细信息" + ) + self._create_message_log(employee_id, '1', url) + except Exception as e: + _logger.error(f"上班打卡提醒发送失败:员工={employee_id.name}, 错误={e}") def card_out_comment(self, employee_id, planning_name): data = f"您的班次是{planning_name},您该下班了,记得打卡" url = '#小程序://天投云/XttsPpKg3MEpY7h' - self.sudo().env["wecom.apps"].sync_send_message(category='att', user_id=employee_id.wecom_userid, - description=data, - title="打卡提醒", - url=url, btntxt="详细信息") + + try: + self.sudo().env["wecom.apps"].sync_send_message( + category='att', + user_id=employee_id.wecom_userid, + description=data, + title="打卡提醒", + url=url, + btntxt="详细信息" + ) + self._create_message_log(employee_id, '2', url) + except Exception as e: + _logger.error(f"下班打卡提醒发送失败:员工={employee_id.name}, 错误={e}") + def card_duty_remind(self, employee_id): data = "今天您值班,记得打卡" diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index fdfb97102..e3d627684 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -924,7 +924,6 @@ class AttendanceMessageLog(models.Model): message_url = fields.Char(string="url") - class DetailsTree(models.Model): _name = 'details.tree' _description = '明细表' diff --git a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml index 7545b5f89..56dbdfce2 100644 --- a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml +++ b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml @@ -107,7 +107,7 @@ - +

@@ -235,12 +235,13 @@ - + +