@@ -156,7 +156,7 @@ class HrAttendanceDetail(models.Model):
|
||||
resource_user_ids = employee.resource_calendar_id.resource_user_ids.ids
|
||||
is_resource_user = True if employee.id in resource_user_ids else False
|
||||
# 哺乳人员
|
||||
suckling_employees = employee.breastfeeding_holiday_ids.mapped('employee_id')
|
||||
suckling_employees = employee.resource_calendar_id.breastfeeding_holiday_ids.mapped('employee_id')
|
||||
def get_all_upper_depts(dept):
|
||||
"""递归获取部门及其所有上级部门的ID列表"""
|
||||
dept_ids = [dept.id]
|
||||
@@ -250,11 +250,27 @@ class HrAttendanceDetail(models.Model):
|
||||
|
||||
# 判断是否是哺乳人员
|
||||
if employee in suckling_employees:
|
||||
is_suckling = True
|
||||
else:
|
||||
is_suckling = False
|
||||
# 判断是否是哺乳人员并调整标准打卡时间
|
||||
current_date = fields.Date.to_date(current_data) if current_data else None
|
||||
if current_date:
|
||||
# 查找当天的哺乳假记录(匹配员工+日期范围)
|
||||
breastfeeding_record = self.env['breastfeeding.holiday'].search([
|
||||
('employee_id', '=', employee.id),
|
||||
('calendar_start_time', '<=', current_date),
|
||||
('calendar_end_time', '>=', current_date),
|
||||
], limit=1) # 取当天有效的第一条记录
|
||||
|
||||
is_early_card, is_late_card, is_abnormal, is_warning, absenteeism_card, is_no_card = self.state_judgment(employee, check_in_time, check_out_time, sch_check_in_time, sch_check_out_time, current_data, is_manual, is_suckling)
|
||||
def float_to_datetime(float_time, base_date):
|
||||
"""将float时间(如8.5=8:30)转换为datetime"""
|
||||
if not float_time or not base_date:
|
||||
return None
|
||||
hours = int(float_time)
|
||||
minutes = int((float_time - hours) * 60)
|
||||
return fields.Datetime.to_datetime(f"{base_date} {hours:02d}:{minutes:02d}:00")
|
||||
sch_check_in_time = float_to_datetime(breastfeeding_record.check_in, current_date) - timedelta(hours=8)
|
||||
sch_check_out_time = float_to_datetime(breastfeeding_record.check_out, current_date)- timedelta(hours=8)
|
||||
|
||||
is_early_card, is_late_card, is_abnormal, is_warning, absenteeism_card, is_no_card = self.state_judgment(employee, check_in_time, check_out_time, sch_check_in_time, sch_check_out_time, current_data, is_manual)
|
||||
|
||||
if attendance:
|
||||
attendance.write({
|
||||
@@ -338,7 +354,7 @@ class HrAttendanceDetail(models.Model):
|
||||
minutes = int((hour_float - hours) * 60)
|
||||
return datetime.combine(base_date, datetime.min.time()) + timedelta(hours=hours, minutes=minutes)
|
||||
|
||||
def state_judgment(self, employee, check_in, check_out, start_datetime, end_datetime, current_data, is_manual, is_suckling):
|
||||
def state_judgment(self, employee, check_in, check_out, start_datetime, end_datetime, current_data, is_manual):
|
||||
"""
|
||||
判断打卡状态
|
||||
:param check_in: 签到时间
|
||||
@@ -347,7 +363,6 @@ class HrAttendanceDetail(models.Model):
|
||||
:param end_datetime: 标准下班打卡时间
|
||||
:param current_data: 打卡日期
|
||||
:param is_manual: 是否为手工补录
|
||||
:param is_suckling: 是否为哺乳人员
|
||||
:return: is_early_card, is_late_card, is_abnormal, is_warning, absenteeism_card
|
||||
"""
|
||||
is_early_card = False
|
||||
@@ -369,40 +384,6 @@ class HrAttendanceDetail(models.Model):
|
||||
start_datetime = remove_seconds(start_datetime)
|
||||
end_datetime = remove_seconds(end_datetime)
|
||||
|
||||
# 新增:判断是否是哺乳人员并调整标准打卡时间
|
||||
if is_suckling and employee.breastfeeding_holiday_ids:
|
||||
# 转换当前打卡日期为date类型(确保与calendar_start_time比较)
|
||||
current_date = fields.Date.to_date(current_data) if current_data else None
|
||||
if current_date:
|
||||
# 查找当天的哺乳假记录(匹配员工+日期范围)
|
||||
breastfeeding_record = self.env['breastfeeding.holiday'].search([
|
||||
('employee_id', '=', employee.id),
|
||||
('calendar_start_time', '<=', current_date),
|
||||
('calendar_end_time', '>=', current_date),
|
||||
], limit=1) # 取当天有效的第一条记录
|
||||
|
||||
# 若找到记录,且打卡时间在哺乳假范围内,则使用记录中的check_in/check_out作为标准时间
|
||||
if breastfeeding_record:
|
||||
# 转换哺乳记录中的float时间为datetime(假设基于current_date)
|
||||
def float_to_datetime(float_time, base_date):
|
||||
"""将float时间(如8.5=8:30)转换为datetime"""
|
||||
if not float_time or not base_date:
|
||||
return None
|
||||
hours = int(float_time)
|
||||
minutes = int((float_time - hours) * 60)
|
||||
return fields.Datetime.to_datetime(f"{base_date} {hours:02d}:{minutes:02d}:00")
|
||||
|
||||
# 转换哺乳记录中的check_in/check_out为datetime
|
||||
bf_check_in = float_to_datetime(breastfeeding_record.check_in, current_date)
|
||||
bf_check_out = float_to_datetime(breastfeeding_record.check_out, current_date)
|
||||
|
||||
# 若打卡时间在哺乳假日期范围内,更新标准时间
|
||||
if bf_check_in and bf_check_out:
|
||||
# 检查实际打卡时间是否在哺乳假的日期范围内
|
||||
if check_in and bf_check_in <= check_in <= bf_check_out:
|
||||
start_datetime = bf_check_in # 标准上班时间改为哺乳记录的check_in
|
||||
end_datetime = bf_check_out # 标准下班时间改为哺乳记录的check_out
|
||||
|
||||
if employee.department_id and employee.department_id.name == '厨卫':
|
||||
start_datetime = start_datetime.replace(hour=1, minute=0, second=0, microsecond=0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user