From 2802b03167b3686fbe2ad12c0f2cb45f4a91cb8f Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Tue, 19 Aug 2025 20:04:23 +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 | 36 ++----------------- .../models/hr_attendance_detail_wechat.py | 15 +++----- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index a4bdefbb8..3cb7aeded 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -80,40 +80,8 @@ class HrAttendance(models.Model): def compute_attendance_ids(self): for att in self.env["hr.attendance"].browse(self._context.get('active_ids', self._context.get('active_id'))): - current_data = fields.Date.today() + timedelta(hours=8) - self.env["hr.attendance.detail"].compute_attendance_detail(att.employee_id, current_data) - - @api.constrains('check_in', 'check_out', 'employee_id') - def _check_validity(self): - """重写验证方法,移除未签退记录的检查""" - for attendance in self: - last_attendance_before_check_in = self.env['hr.attendance'].search([ - ('employee_id', '=', attendance.employee_id.id), - ('check_in', '<=', attendance.check_in), - ('id', '!=', attendance.id), - ], order='check_in desc', limit=1) - - if last_attendance_before_check_in and last_attendance_before_check_in.check_out and last_attendance_before_check_in.check_out > attendance.check_in: - raise exceptions.ValidationError(_( - "Cannot create new attendance record for %(empl_name)s, the employee was already checked in on %(datetime)s", - empl_name=attendance.employee_id.name, - datetime=format_datetime(self.env, attendance.check_in, dt_format=False) - )) - if attendance.check_out: - last_attendance_before_check_out = self.env['hr.attendance'].search([ - ('employee_id', '=', attendance.employee_id.id), - ('check_in', '<', attendance.check_out), - ('id', '!=', attendance.id), - ], order='check_in desc', limit=1) - if last_attendance_before_check_out and last_attendance_before_check_in != last_attendance_before_check_out: - raise exceptions.ValidationError(_( - "Cannot create new attendance record for %(empl_name)s, the employee was already checked in on %(datetime)s", - empl_name=attendance.employee_id.name, - datetime=format_datetime(self.env, last_attendance_before_check_out.check_in, dt_format=False) - )) - - - + current_data = fields.Datetime.to_datetime(att.current_data) + timedelta(hours=8) + self.env["hr.attendance.detail"].compute_attendance_detail(att.employee_id, current_data.date()) @api.depends('current_data') def _compute_month_status(self): diff --git a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py index 1aafc35d1..782350018 100644 --- a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py +++ b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py @@ -117,14 +117,9 @@ class HrAttendanceDetail(models.Model): ('employee_id', '=', record.employee_id.id), ('current_data', '=', checkin_date) ], limit=1) - if attendance: - if not attendance.check_in: - attendance.check_in = record.checkin_time - attendance.check_out = record.checkin_time - else: - now_time = fields.Datetime.to_datetime(checkin_date) + timedelta(hours=8, days=1) - start_time = now_time - timedelta(days=2) - self.env["hr.attendance.detail"].get_hr_attendance_time(record.employee_id, now_time, start_time) + + current_data = fields.Datetime.to_datetime(checkin_date) + timedelta(hours=8) + self.env["hr.attendance.detail"].compute_attendance_detail(record.employee_id, current_data.date()) def compute_attendance_detail(self, employee, current_data): """重新计算逻辑 @@ -222,10 +217,10 @@ class HrAttendanceDetail(models.Model): end_minute = int((check_out_end - end_hour) * 60) start_datetime = datetime.combine(date, datetime.min.time()).replace( hour=start_hour, minute=start_minute, second=0, microsecond=0 - ) + ) - timedelta(hours=8) end_datetime = datetime.combine(date, datetime.min.time()).replace( hour=end_hour, minute=end_minute, second=0, microsecond=0 - ) + ) - timedelta(hours=8) return start_datetime, end_datetime def float_to_datetime(self, base_date, hour_float):