1
This commit is contained in:
@@ -203,9 +203,17 @@ class AppletAttendance(Controller):
|
||||
}
|
||||
"""
|
||||
user_id = int(kw['user_id'])
|
||||
month = int(kw['selected_month'])
|
||||
now = datetime.now()
|
||||
calendar_leaves = request.env(user=SUPERUSER_ID)['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")])
|
||||
month = kw['selected_month'] # 2015-01
|
||||
year = month[0:4]
|
||||
month = month[-2:]
|
||||
# 当月日期范围
|
||||
current_month_first = datetime(year, month, 1)
|
||||
if month == 12:
|
||||
current_month_last = datetime(year + 1, 1, 1) - timedelta(days=1)
|
||||
else:
|
||||
current_month_last = datetime(year, month + 1, 1) - timedelta(days=1)
|
||||
|
||||
calendar_leaves = request.env(user=SUPERUSER_ID)['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")]) # 少一个search
|
||||
holidays_list = [] # 假期
|
||||
shift_days_list = [] # 调休
|
||||
for leaves in calendar_leaves:
|
||||
@@ -219,20 +227,7 @@ class AppletAttendance(Controller):
|
||||
"holiday_list": holidays_list,
|
||||
"shift_days_list": shift_days_list,
|
||||
}
|
||||
# 当月日期范围
|
||||
current_month_first = datetime(now.year, now.month, 1)
|
||||
if now.month == 12:
|
||||
current_month_last = datetime(now.year + 1, 1, 1) - timedelta(days=1)
|
||||
else:
|
||||
current_month_last = datetime(now.year, now.month + 1, 1) - timedelta(days=1)
|
||||
# 上个月日期范围
|
||||
if now.month == 1:
|
||||
prev_month_first = datetime(now.year - 1, 12, 1)
|
||||
prev_month_last = datetime(now.year, 1, 1) - timedelta(days=1)
|
||||
else:
|
||||
prev_month_first = datetime(now.year, now.month - 1, 1)
|
||||
prev_month_last = current_month_first - timedelta(days=1)
|
||||
# 当月考勤记录
|
||||
# 本月考勤记录
|
||||
current_attendance = request.env(user=SUPERUSER_ID)['hr.attendance'].sudo().search([
|
||||
('employee_id.user_id', '=', user_id),
|
||||
('current_data', '>=', current_month_first.date()),
|
||||
@@ -250,53 +245,18 @@ class AppletAttendance(Controller):
|
||||
'is_go_away': sum(1 for rec in current_attendance if rec.is_abnormal),
|
||||
'is_no_work': sum(1 for rec in current_attendance if rec.is_abnormal),
|
||||
}
|
||||
# 上月考勤记录
|
||||
prev_attendance = request.env(user=SUPERUSER_ID)['hr.attendance'].sudo().search([
|
||||
('employee_id.user_id', '=', user_id),
|
||||
('current_data', '>=', prev_month_first.date()),
|
||||
('current_data', '<=', prev_month_last.date()),
|
||||
('week', 'not in', ['seven', 'six'])
|
||||
])
|
||||
# 上月异常次数
|
||||
prev_stats = {
|
||||
'is_no_card': sum(1 for rec in prev_attendance if rec.is_no_card),
|
||||
'is_early_card': sum(1 for rec in prev_attendance if rec.is_early_card),
|
||||
'is_late_card': sum(1 for rec in prev_attendance if rec.is_late_card),
|
||||
'is_abnormal': sum(1 for rec in prev_attendance if rec.is_abnormal),
|
||||
# !!!!!!
|
||||
'is_holiday': sum(1 for rec in current_attendance if rec.is_abnormal),
|
||||
'is_go_away': sum(1 for rec in current_attendance if rec.is_abnormal),
|
||||
'is_no_work': sum(1 for rec in current_attendance if rec.is_abnormal),
|
||||
}
|
||||
# 处理当月和上月记录
|
||||
current_records = self.process_attendances(current_attendance, user_id)
|
||||
prev_records = self.process_attendances(prev_attendance, user_id)
|
||||
if month[-2:-1] == fields.Date.today().month:
|
||||
return_data = {
|
||||
'code': '200',
|
||||
'message': 'OK',
|
||||
'data': {
|
||||
'current_month': {
|
||||
'holiday_data': holiday_data,
|
||||
'banner_rote': current_stats,
|
||||
'attendance_data': current_records,
|
||||
},
|
||||
}
|
||||
return_data = {
|
||||
'code': '200',
|
||||
'message': 'OK',
|
||||
'data': {
|
||||
'current_month': {
|
||||
'holiday_data': holiday_data,
|
||||
'banner_rote': current_stats,
|
||||
'attendance_data': current_records,
|
||||
},
|
||||
}
|
||||
elif month[-2:-1] == fields.Date.today().month - 1:
|
||||
return_data = {
|
||||
'code': '200',
|
||||
'message': 'OK',
|
||||
'data': {
|
||||
'current_month': {
|
||||
'holiday_data': holiday_data,
|
||||
'banner_rote': prev_stats,
|
||||
'attendance_data': prev_records,
|
||||
}
|
||||
}
|
||||
}
|
||||
else:
|
||||
return_data = {'code': '300', 'message': '月份异常'}
|
||||
}
|
||||
return json.dumps(return_data)
|
||||
|
||||
# 处理考勤记录
|
||||
@@ -334,16 +294,18 @@ class AppletAttendance(Controller):
|
||||
check_out_str = check_out.strftime('%H:%M:%S') if check_out else '未打卡'
|
||||
def get_status_color(status):
|
||||
return 'red' if status in ['迟到', '早退', '未打卡'] else 'green'
|
||||
check_in_html = f'<p style="color:{get_status_color(check_in_status)}">{check_in_str} {check_in_status}</p>'
|
||||
check_out_html = f'<p style="color:{get_status_color(check_out_status)}">{check_out_str} {check_out_status}</p>'
|
||||
check_in_html = f'<p style="color:{get_status_color(check_in_status)}">{check_in_status}</p>'
|
||||
check_out_html = f'<p style="color:{get_status_color(check_out_status)}">{check_out_status}</p>'
|
||||
|
||||
# 添加到记录列表
|
||||
records.append({
|
||||
'date': att.current_data.strftime('%Y-%m-%d'),
|
||||
'class': [shift_name, f"{standard_check_in_str}-{standard_check_out_str}"],
|
||||
'user_id': user_id,
|
||||
'check_in': check_in_html,
|
||||
'check_out': check_out_html,
|
||||
'check_in': check_in_str,
|
||||
'check_in_state': check_in_html,
|
||||
'check_out': check_out_str,
|
||||
'check_out_state': check_out_html,
|
||||
})
|
||||
return records
|
||||
|
||||
|
||||
Reference in New Issue
Block a user