添加功能

This commit is contained in:
zhou
2025-08-19 20:04:23 +08:00
parent 50a44dc42a
commit 2802b03167
2 changed files with 7 additions and 44 deletions
+2 -34
View File
@@ -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):
@@ -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):