添加功能
This commit is contained in:
@@ -304,40 +304,6 @@ class AppletAttendance(Controller):
|
||||
return_data = {'data': data, 'code': '200', 'message': '成功', }
|
||||
return json.dumps(return_data)
|
||||
|
||||
def is_workday(self, date):
|
||||
"""判断指定日期是否为工作日(考虑法定节假日和调休)
|
||||
如果是工作日返回True
|
||||
如果是休息日返回False
|
||||
"""
|
||||
current_year = (fields.Date.today() + timedelta(hours=8)).year
|
||||
query_start = datetime(current_year, 1, 1, 0, 0, 0) - timedelta(hours=8)
|
||||
query_end = datetime(current_year, 12, 31, 23, 59, 59) - timedelta(hours=8)
|
||||
calendar_leaves = request.env['resource.calendar.leaves'].sudo().search([
|
||||
("calendar_id.name", "=", "行政考勤工作日"),
|
||||
("date_from", ">=", query_start),
|
||||
("date_from", "<=", query_end)
|
||||
])
|
||||
holidays_set = set()
|
||||
shift_days_set = set()
|
||||
for leave in calendar_leaves:
|
||||
if leave.holidays:
|
||||
holidays_set.update(leave.holidays.split(','))
|
||||
if leave.alternate_rest_day:
|
||||
holidays_set.update(leave.alternate_rest_day.split(','))
|
||||
if leave.shift_replacement_day:
|
||||
shift_days_set.update(leave.shift_replacement_day.split(','))
|
||||
|
||||
date_str = date.strftime('%m月%d日')
|
||||
date_str = self.remove_leading_zero(date_str)
|
||||
is_weekend = date.weekday() in [5, 6]
|
||||
|
||||
if date_str in holidays_set:
|
||||
return False
|
||||
elif date_str in shift_days_set:
|
||||
return True
|
||||
else:
|
||||
return not is_weekend
|
||||
|
||||
def remove_leading_zero(self, date_str):
|
||||
month, day = date_str.split('月')
|
||||
month = month.lstrip('0')
|
||||
@@ -672,7 +638,7 @@ class AppletAttendance(Controller):
|
||||
def process_attendances(self, attendances, user_id):
|
||||
records = []
|
||||
for att in attendances:
|
||||
is_weekend = att.current_data.weekday() in [5, 6]
|
||||
is_weekend = self.is_weekend(att.current_data)
|
||||
|
||||
if not att.shift_id:
|
||||
year = att.current_data.year
|
||||
@@ -708,9 +674,12 @@ class AppletAttendance(Controller):
|
||||
check_out = att.check_out
|
||||
is_early_card = att.is_early_card
|
||||
is_late_card = att.is_late_card
|
||||
is_work = att.is_work
|
||||
base_check_in_status = '旷工' if is_work else (
|
||||
'缺卡' if not check_in else ('迟到' if is_late_card else '正常'))
|
||||
base_check_out_status = '旷工' if is_work else (
|
||||
'缺卡' if not check_out else ('早退' if is_early_card else '正常'))
|
||||
|
||||
base_check_in_status = '缺卡' if not check_in else ('迟到' if is_late_card else '正常')
|
||||
base_check_out_status = '缺卡' if not check_out else ('早退' if is_early_card else '正常')
|
||||
|
||||
if is_weekend:
|
||||
check_in_status = '正常' if check_in else ''
|
||||
@@ -722,28 +691,28 @@ class AppletAttendance(Controller):
|
||||
if check_in:
|
||||
check_in_time = (check_in + timedelta(hours=8)).strftime('%H:%M:%S')
|
||||
check_in_str = f"{check_in_status} {check_in_time}" if check_in_status in ['迟到',
|
||||
'早退'] else check_in_time
|
||||
'早退', '旷工'] else check_in_time
|
||||
else:
|
||||
check_in_str = '' if is_weekend else '缺卡'
|
||||
|
||||
if check_out:
|
||||
check_out_time = (check_out + timedelta(hours=8)).strftime('%H:%M:%S')
|
||||
check_out_str = f"{check_out_status} {check_out_time}" if check_out_status in ['迟到',
|
||||
'早退'] else check_out_time
|
||||
'早退', '旷工'] else check_out_time
|
||||
else:
|
||||
check_out_str = '' if is_weekend else '缺卡'
|
||||
|
||||
if not check_in_status and not check_out_status:
|
||||
color_select = 3
|
||||
else:
|
||||
has_exception = (check_in_status in ['迟到', '早退', '缺卡']) or (
|
||||
check_out_status in ['迟到', '早退', '缺卡'])
|
||||
has_exception = (check_in_status in ['迟到', '早退', '缺卡', '旷工']) or (
|
||||
check_out_status in ['迟到', '早退', '缺卡', '旷工'])
|
||||
|
||||
color_select = 2 if has_exception else 1
|
||||
|
||||
records.append({
|
||||
'date': att.current_data.strftime('%Y/%m/%d'),
|
||||
'class': [f"{att.shift_name} ", f"{standard_check_in_str}-{standard_check_out_str}"],
|
||||
'class': [f"{att.shift_name}", f"{standard_check_in_str}-{standard_check_out_str}"],
|
||||
'user_id': user_id,
|
||||
'check_in': check_in_str,
|
||||
'check_out': check_out_str,
|
||||
@@ -1360,3 +1329,38 @@ class AppletAttendance(Controller):
|
||||
'code': 200,
|
||||
'message': '成功'
|
||||
})
|
||||
|
||||
|
||||
def is_workday(self, date):
|
||||
"""判断指定日期是否为工作日(考虑法定节假日和调休)
|
||||
如果是工作日返回True
|
||||
如果是休息日返回False
|
||||
"""
|
||||
current_year = (fields.Date.today() + timedelta(hours=8)).year
|
||||
query_start = datetime(current_year, 1, 1, 0, 0, 0) - timedelta(hours=8)
|
||||
query_end = datetime(current_year, 12, 31, 23, 59, 59) - timedelta(hours=8)
|
||||
calendar_leaves = request.env['resource.calendar.leaves'].sudo().search([
|
||||
("calendar_id.name", "=", "行政考勤工作日"),
|
||||
("date_from", ">=", query_start),
|
||||
("date_from", "<=", query_end)
|
||||
])
|
||||
holidays_set = set()
|
||||
shift_days_set = set()
|
||||
for leave in calendar_leaves:
|
||||
if leave.holidays:
|
||||
holidays_set.update(leave.holidays.split(','))
|
||||
if leave.alternate_rest_day:
|
||||
holidays_set.update(leave.alternate_rest_day.split(','))
|
||||
if leave.shift_replacement_day:
|
||||
shift_days_set.update(leave.shift_replacement_day.split(','))
|
||||
|
||||
date_str = date.strftime('%m月%d日')
|
||||
date_str = self.remove_leading_zero(date_str)
|
||||
is_weekend = date.weekday() in [5, 6]
|
||||
|
||||
if date_str in holidays_set:
|
||||
return False
|
||||
elif date_str in shift_days_set:
|
||||
return True
|
||||
else:
|
||||
return not is_weekend
|
||||
Reference in New Issue
Block a user