| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- """审批轮次过滤 — 驳回后重新提交时,进度接口仅展示当前轮次。"""
- from __future__ import annotations
- from datetime import datetime
- from typing import List, Sequence, TypeVar
- T = TypeVar("T")
- def filter_current_cycle_approvals(
- approvals: Sequence[T],
- apply_status: str,
- *,
- status_attr: str = "approval_status",
- time_attr: str = "approval_time",
- ) -> List[T]:
- """审批进度仅展示当前轮次;完整历史由 get_approval_history 返回。"""
- rejections = [a for a in approvals if getattr(a, status_attr) == "rejected"]
- if not rejections:
- return list(approvals)
- sorted_rejections = sorted(
- rejections,
- key=lambda a: getattr(a, time_attr) or datetime.min,
- )
- last_rejection_time = getattr(sorted_rejections[-1], time_attr) or datetime.min
- if apply_status != "rejected":
- return [
- a
- for a in approvals
- if (getattr(a, time_attr) or datetime.min) > last_rejection_time
- ]
- cycle_start = datetime.min
- if len(sorted_rejections) >= 2:
- cycle_start = getattr(sorted_rejections[-2], time_attr) or datetime.min
- return [
- a
- for a in approvals
- if (getattr(a, time_attr) or datetime.min) > cycle_start
- ]
|