75 lines
2.9 KiB
Python
75 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
||
"""单据详情页「我的抄送」那一格的挑人逻辑:纯内存校验,不连库、不写任何数据。
|
||
|
||
``_my_cc_brief`` 从已经读回来的两张待阅表里挑一条给详情页右栏那张卡。
|
||
它只认登录账号、欠账优先、已办完回显最近那条,同单多条要报 others。
|
||
这里用几行假对象把三条口径钉住,**没有任何数据库访问**,所以开发/测试/生产
|
||
环境都碰不到——跑这一条脚本不会在任何环境留下痕迹::
|
||
|
||
PYTHONPATH=. python3 scripts/check_my_cc_brief.py
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
from datetime import datetime
|
||
|
||
from app.api.runtime import _my_cc_brief
|
||
from app import models
|
||
|
||
|
||
def read(identity: str, start: str, *, requires_action: bool = True, handled: bool = False,
|
||
completed: bool = False, attachments: list | None = None):
|
||
cls = models.ReadCompleted if completed else models.Read
|
||
row = cls(
|
||
id=f"rd-{identity}-{start}",
|
||
job="JOB-1",
|
||
work="W-1",
|
||
title="单据",
|
||
process="P-1",
|
||
process_name="流程",
|
||
serial="S-1",
|
||
identity=identity,
|
||
identity_name="姓名",
|
||
sender="陈妮",
|
||
opinion="请核对",
|
||
read_type="cc",
|
||
requires_action=requires_action,
|
||
handle_time=datetime(2026, 11, 24, 10, 5) if handled else None,
|
||
attachments=attachments or [],
|
||
start_time=datetime.fromisoformat(start),
|
||
)
|
||
# 这几列老库里未必都有,序列化器用 getattr 兜空串;假对象不设也不影响这一格的判定
|
||
return row
|
||
|
||
|
||
def main() -> int:
|
||
# 别人的单:一像素不摆
|
||
assert _my_cc_brief([read("other", "2026-11-24 09:00:00")], "me") is None
|
||
|
||
# 欠账优先:两条需处理,一条已办、一条未办,挑未办那条
|
||
done = read("me", "2026-11-24 09:00:00", handled=True, completed=True)
|
||
pending = read("me", "2026-11-24 11:00:00")
|
||
brief = _my_cc_brief([done, pending], "me")
|
||
assert brief is not None and brief["id"] == pending.id
|
||
assert brief["requires_action"] and not brief["handled"] and not brief["completed"]
|
||
assert brief["other_count"] == 1
|
||
|
||
# 都办完了:回显最近那条(含处理意见时刻)
|
||
later = read("me", "2026-11-24 12:00:00", handled=True, completed=True)
|
||
brief = _my_cc_brief([done, later], "me")
|
||
assert brief is not None and brief["id"] == later.id
|
||
assert brief["handled"] and brief["completed"] and brief["handle_time"]
|
||
|
||
# 只需阅:不摆提交钮的判据靠 requires_action,这一格原样带出去
|
||
only_read = read("me", "2026-11-24 09:00:00", requires_action=False)
|
||
brief = _my_cc_brief([only_read], "me")
|
||
assert brief is not None and not brief["requires_action"] and not brief["handled"]
|
||
|
||
print("check_my_cc_brief: OK(纯内存,零数据库访问)")
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|