feat(overtime): add special half-day overtime rule for functional scheduling

新增职能排班员工休息日/节假日加班的半天时长规则:上午加班按3.5小时、下午按4.5小时计算,不再统一使用4小时的默认半天标准,按加班开始时间是否早于12点区分上下午。
This commit is contained in:
2026-08-12 09:31:10 +08:00
parent 9927066abb
commit 9a14f5aca6
3 changed files with 78 additions and 2 deletions
+38 -1
View File
@@ -93,6 +93,12 @@ OT_REVIEW_DAYS = 8
# 月度截止:每月该日期 12:00 之后,不再审核上一个月的加班流程
MONTH_CUTOFF_DAY = 2
MONTH_CUTOFF_HOUR = 12
# 职能排班半天加班时长:上午3.5小时、下午4.5小时
# (休息日/节假日加班,不再统一按4小时半天处理,整天仍为9小时)
ZHINENG_HALF_MORNING_HOURS = 3.5
ZHINENG_HALF_AFTERNOON_HOURS = 4.5
# 职能排班上午/下午分界:申请加班开始时间早于该时刻(12点)视为上午半天
ZHINENG_HALF_CUTOFF_HOUR = 12
# ---------- 分页 ----------
DEFAULT_PAGE_SIZE = 15
@@ -1115,6 +1121,27 @@ def _get_shift(session, staff_id, date_str):
return "获取失败"
def _is_zhineng_schedule(session, staff_id, date_str):
"""
判断员工是否为职能排班(休息日/节假日加班半天规则专用)。
不看加班当天(当天排班通常显示'休息'),而是查看当月排班日历中的其他天:
只要任一班次包含'职能'(如 职能正班A),即按职能排班处理。
排班获取失败时优雅降级返回 False,沿用默认半天4小时规则。
"""
if not date_str or not staff_id:
return False
try:
year = int(date_str[:4])
month = int(date_str[5:7])
html = get_attendance_html(session, staff_id, year, month)
attendance = parse_attendance_html(html)
return any("职能" in (shift or "") for shift in attendance.values())
except Exception as e:
logger.warning("获取排班判断职能失败(%s): %s", date_str, str(e))
return False
def _check_attendance(session, staff_id, ot_date):
return {"加班当天班次": _get_shift(session, staff_id, ot_date)}
@@ -1325,8 +1352,18 @@ def _validate_day_ot(info, punch, session, staff_id, require_holiday):
reasons.append("申报天数缺失或为0")
elif interval is not None:
threshold = _calc_day_ot_threshold(apply_days)
# 职能排班半天(0.5天)加班:上午3.5小时、下午4.5小时,不再统一按4小时半天处理;
# 上/下午按申请加班开始时间判定(早于12:00视为上午半天)
if abs(apply_days - 0.5) < 1e-9 and _is_zhineng_schedule(session, staff_id, ot_date):
start = _parse_dt(info.get("加班开始时间"))
if start is not None and start.hour < ZHINENG_HALF_CUTOFF_HOUR:
threshold = ZHINENG_HALF_MORNING_HOURS
else:
threshold = ZHINENG_HALF_AFTERNOON_HOURS
if interval < threshold:
reasons.append(f"打卡间隔{interval:.2f}小时不足申报{apply_days:g}天所需的{threshold:g}小时")
reasons.append(
f"打卡间隔{interval:.2f}小时不足申报{apply_days:g}天所需的{threshold:g}小时"
)
info["打卡时间间隔(小时)"] = interval
info["申报天数(天)"] = apply_days