!3385 添加功能

Merge pull request !3385 from 李鹏宇/dev_zhou
This commit is contained in:
李鹏宇
2025-06-18 08:33:58 +00:00
committed by Gitee
@@ -5,7 +5,7 @@ import logging
from geopy.distance import geodesic
from datetime import timedelta
import json
from dateutil.relativedelta import relativedelta
_logger = logging.getLogger(__name__)
@@ -214,19 +214,8 @@ class AppletAttendance(Controller):
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:
if leaves.holidays:
holidays_list.extend(leaves.holidays.split(',')) # 法定节假日
if leaves.shift_replacement_day:
shift_days_list.extend(leaves.shift_replacement_day.split(',')) # 调班补班
if leaves.alternate_rest_day:
holidays_list.extend(leaves.alternate_rest_day.split(',')) # 调休日
holiday_data = {
"holiday_list": holidays_list,
"shift_days_list": shift_days_list,
}
# 本月的节假日
holiday_data = self.get_holiday_data(current_month_first.date(), current_month_last.date())
# 本月考勤记录
current_attendance = request.env(user=SUPERUSER_ID)['hr.attendance'].sudo().search([
('employee_id.user_id', '=', user_id),
@@ -309,7 +298,65 @@ class AppletAttendance(Controller):
})
return records
# 水电表接口
def get_holiday_data(self, start_date, end_date):
"""
获取指定日期范围内的假期和调休数据
参数:
start_date: 开始日期,date类型
end_date: 结束日期,date类型
返回:
包含假期和调休信息的字典
"""
# 从start_date中提取年份
current_year = start_date.year
domain = [("calendar_id", "=", "行政考勤工作日")]
if start_date and end_date:
# 将date对象转换为datetime对象
start_datetime = datetime.combine(start_date, datetime.min.time())
end_datetime = datetime.combine(end_date, datetime.max.time())
domain.extend([
("date_from", "<=", end_datetime),
("date_to", ">=", start_datetime)
])
calendar_leaves = request.env(user=SUPERUSER_ID)['resource.calendar.leaves'].search(domain)
holidays_list = [] # 假期
shift_days_list = [] # 调休
for leaves in calendar_leaves:
# 处理法定节假日和调休日- 直接从date_from和date_to获取
if leaves.date_from and leaves.date_to:
# 将datetime类型转换为date类型并格式化为YYYY-MM-DD
date_from = leaves.date_from.date().isoformat()
date_to = leaves.date_to.date().isoformat()
# 如果是同一天,只添加一次
if date_from == date_to:
holidays_list.append(date_from)
else:
# 处理日期范围,添加从date_from到date_to的所有日期
start_date_obj = datetime.strptime(date_from, '%Y-%m-%d').date()
end_date_obj = datetime.strptime(date_to, '%Y-%m-%d').date()
delta = end_date_obj - start_date_obj
for i in range(delta.days + 1):
day = start_date_obj + timedelta(days=i)
holidays_list.append(day.isoformat())
# 处理调班补班
if leaves.shift_replacement_day:
for shift_day in leaves.shift_replacement_day.split(','):
month, day = shift_day.replace('月', '').replace('日', '').split()
formatted_date = f"{current_year}-{int(month):02d}-{int(day):02d}"
shift_days_list.append(formatted_date)
return {
"holiday_list": holidays_list,
"shift_days_list": shift_days_list,
}
# 水电表接口
@route('/yuthon/meter/reading', methods=['POST'], type='http', auth='none', cors='*', csrf=False)
def yuthon_meter_reading(self, **kw):
"""