提交
This commit is contained in:
1 parent
48dcf991dc
commit
be2226e4ca
100 files changed
+61340
-40975
No files matched your search
@@ -19,6 +19,29 @@ def _status(row: Mapping[str, Any], *keys: str) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _schedule_id(row: Mapping[str, Any]) -> str:
|
||||
return str(row.get("id") or row.get("scheduleId") or row.get("schedule_id") or "").strip()
|
||||
|
||||
|
||||
def _transfer_schedule_id(row: Mapping[str, Any]) -> str:
|
||||
return str(row.get("scheduleId") or row.get("schedule_id") or "").strip()
|
||||
|
||||
|
||||
def is_schedule_effectively_cleared(
|
||||
schedule: Mapping[str, Any],
|
||||
*,
|
||||
confirmed_paid: Decimal,
|
||||
) -> bool:
|
||||
"""
|
||||
批次已缴清:显式 cleared,或财务确认实缴(yjf)已覆盖应缴。
|
||||
兼容历史数据未回写 schedule_status 的情况。
|
||||
"""
|
||||
if _status(schedule, "scheduleStatus", "schedule_status") == "cleared":
|
||||
return True
|
||||
due = _dec(schedule.get("dueAmount", schedule.get("due_amount")))
|
||||
return confirmed_paid >= due
|
||||
|
||||
|
||||
def compute_sample_payment_progress(
|
||||
*,
|
||||
schedules: Iterable[Mapping[str, Any]],
|
||||
@@ -27,31 +50,38 @@ def compute_sample_payment_progress(
|
||||
"""
|
||||
progressStatus 优先级:yjq > bfyj > dfj(不含付款确认中)
|
||||
已缴仅计 pay_status=yjf;有效期排除 schedule_status=void
|
||||
已缴清期:schedule_status=cleared,或该期 yjf 合计 >= 应缴
|
||||
canConfirm:无 jfqrz,且存在有效未清期
|
||||
"""
|
||||
sch_list: List[Mapping[str, Any]] = list(schedules or [])
|
||||
tr_list: List[Mapping[str, Any]] = list(transfers or [])
|
||||
|
||||
paid_by_schedule: Dict[str, Decimal] = {}
|
||||
paid = Decimal("0")
|
||||
for t in tr_list:
|
||||
if _status(t, "payStatus", "pay_status") != "yjf":
|
||||
continue
|
||||
amount = _dec(t.get("transferAmount", t.get("transfer_amount")))
|
||||
paid += amount
|
||||
sid = _transfer_schedule_id(t)
|
||||
if sid:
|
||||
paid_by_schedule[sid] = paid_by_schedule.get(sid, Decimal("0")) + amount
|
||||
|
||||
active = [
|
||||
s
|
||||
for s in sch_list
|
||||
if _status(s, "scheduleStatus", "schedule_status") != "void"
|
||||
]
|
||||
active_schedule_count = len(active)
|
||||
cleared_schedule_count = sum(
|
||||
1
|
||||
cleared_flags = [
|
||||
is_schedule_effectively_cleared(
|
||||
s,
|
||||
confirmed_paid=paid_by_schedule.get(_schedule_id(s), Decimal("0")),
|
||||
)
|
||||
for s in active
|
||||
if _status(s, "scheduleStatus", "schedule_status") == "cleared"
|
||||
)
|
||||
]
|
||||
cleared_schedule_count = sum(1 for cleared in cleared_flags if cleared)
|
||||
|
||||
paid = sum(
|
||||
(
|
||||
_dec(t.get("transferAmount", t.get("transfer_amount")))
|
||||
for t in tr_list
|
||||
if _status(t, "payStatus", "pay_status") == "yjf"
|
||||
),
|
||||
Decimal("0"),
|
||||
)
|
||||
due_total = sum((_dec(s.get("dueAmount", s.get("due_amount"))) for s in active), Decimal("0"))
|
||||
due_remain = due_total - paid
|
||||
if due_remain < 0:
|
||||
@@ -66,9 +96,7 @@ def compute_sample_payment_progress(
|
||||
else:
|
||||
progress = "dfj"
|
||||
|
||||
can_confirm = (not has_jfqrz) and any(
|
||||
_status(s, "scheduleStatus", "schedule_status") != "cleared" for s in active
|
||||
)
|
||||
can_confirm = (not has_jfqrz) and any(not cleared for cleared in cleared_flags)
|
||||
|
||||
return {
|
||||
"progressStatus": progress,
|
||||
|
||||
Reference in new issue
Block a user