fix(pl): 运输归档角标不再统计 2026-09-01 及更早的计划。
菜单数字只计计划日期晚于 2026-09-01、已安排且未归档的计划。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7cef2d0f9d
commit
ff2f05c522
2 files changed
+59
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""运输管理 - 侧栏菜单角标统计"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -115,14 +116,19 @@ def count_legal_use_document_pending(db: Session, tenant_no: str, user) -> int:
|
||||
return apply_pl_scope(query, PlPlan, user, db, tenant_no).count()
|
||||
|
||||
|
||||
# 运输归档角标从该日之后起算,当天及更早的计划不计入。
|
||||
ARCHIVE_BADGE_PLAN_DATE_AFTER = date(2026, 9, 1)
|
||||
|
||||
|
||||
def count_plan_archive_pending(db: Session, tenant_no: str, user) -> int:
|
||||
"""待归档角标:与归档列表一致,仅统计已安排运输且未归档的计划。"""
|
||||
"""待归档角标:已安排运输、未归档,且计划日期晚于 2026-09-01。"""
|
||||
query = db.query(PlPlan).filter(
|
||||
PlPlan.tenant_no == tenant_no,
|
||||
PlPlan.del_flag == 0,
|
||||
PlPlan.archive_status == "unarchived",
|
||||
PlPlan.follow_status != "cancelled",
|
||||
PlPlan.transport_status == "arranged",
|
||||
PlPlan.plan_date > ARCHIVE_BADGE_PLAN_DATE_AFTER,
|
||||
)
|
||||
query = apply_pl_scope(query, PlPlan, user, db, tenant_no)
|
||||
return query.count()
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
"""运输归档角标:计划日期在 2026-09-01 及以前的不计数。"""
|
||||
from datetime import date
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.pl_models import PlPlan
|
||||
from app.services.pl_menu_badge_service import count_plan_archive_pending
|
||||
|
||||
|
||||
def test_archive_badge_skips_plans_on_or_before_2026_09_01():
|
||||
engine = create_engine("sqlite://")
|
||||
PlPlan.__table__.create(engine)
|
||||
db = Session(engine)
|
||||
|
||||
def add(plan_id, plan_date, **extra):
|
||||
fields = dict(
|
||||
id=plan_id,
|
||||
plan_no=plan_id,
|
||||
create_date=date(2026, 9, 2),
|
||||
plan_date=plan_date,
|
||||
belongs_company="shanxia",
|
||||
plan_type="direct",
|
||||
tenant_no="t",
|
||||
transport_status="arranged",
|
||||
archive_status="unarchived",
|
||||
follow_status="arranged",
|
||||
)
|
||||
fields.update(extra)
|
||||
db.add(PlPlan(**fields))
|
||||
|
||||
add("before", date(2026, 8, 31))
|
||||
add("on-cutoff", date(2026, 9, 1))
|
||||
add("after", date(2026, 9, 2))
|
||||
add("blank", None)
|
||||
add("archived", date(2026, 9, 2), archive_status="archived")
|
||||
add("pending", date(2026, 9, 2), transport_status="pending")
|
||||
add("cancelled", date(2026, 9, 2), follow_status="cancelled")
|
||||
db.commit()
|
||||
|
||||
user = SimpleNamespace()
|
||||
with patch(
|
||||
"app.services.pl_menu_badge_service.apply_pl_scope",
|
||||
side_effect=lambda query, *args, **kwargs: query,
|
||||
):
|
||||
total = count_plan_archive_pending(db, "t", user)
|
||||
|
||||
assert total == 1
|
||||
db.close()
|
||||
engine.dispose()
|
||||
Reference in new issue
Block a user