93 lines
2.7 KiB
Python
93 lines
2.7 KiB
Python
"""首页「ETC/加油充值审批」角标:统计当前用户待审批单据数。"""
|
|
from datetime import date
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from app.models.bx_models import BxWorkflowDef, BxWorkflowNode
|
|
from app.models.pl_models import PlVehicleRechargeApply
|
|
from app.services.pl_menu_badge_service import (
|
|
MENU_CODE_RECHARGE_APPROVAL,
|
|
build_menu_badge_counts,
|
|
)
|
|
|
|
|
|
def test_recharge_approval_badge_counts_current_approver_pending(monkeypatch):
|
|
engine = create_engine("sqlite://")
|
|
BxWorkflowDef.__table__.create(engine)
|
|
BxWorkflowNode.__table__.create(engine)
|
|
PlVehicleRechargeApply.__table__.create(engine)
|
|
db = sessionmaker(bind=engine)()
|
|
|
|
db.add(
|
|
BxWorkflowDef(
|
|
id="wf1",
|
|
biz_type="vehicle_recharge",
|
|
wf_name="充值审批",
|
|
tenant_no="t1",
|
|
create_dept_id="d1",
|
|
)
|
|
)
|
|
db.add(
|
|
BxWorkflowNode(
|
|
id="node-me",
|
|
wf_id="wf1",
|
|
node_name="总经理",
|
|
node_order=1,
|
|
approver_id="u-me",
|
|
action_type="approve",
|
|
tenant_no="t1",
|
|
create_dept_id="d1",
|
|
)
|
|
)
|
|
db.add(
|
|
BxWorkflowNode(
|
|
id="node-other",
|
|
wf_id="wf1",
|
|
node_name="财务",
|
|
node_order=2,
|
|
approver_id="u-other",
|
|
action_type="disburse",
|
|
tenant_no="t1",
|
|
create_dept_id="d1",
|
|
)
|
|
)
|
|
|
|
def add_apply(row_id: str, *, status: str, current_node: Optional[str]) -> None:
|
|
db.add(
|
|
PlVehicleRechargeApply(
|
|
id=row_id,
|
|
apply_no=f"NO-{row_id}",
|
|
license_plate="鄂A00001",
|
|
recharge_type="fuel",
|
|
apply_date=date(2026, 9, 1),
|
|
applicant_id="u1",
|
|
status=status,
|
|
current_node=current_node,
|
|
tenant_no="t1",
|
|
create_dept_id="d1",
|
|
)
|
|
)
|
|
|
|
add_apply("a1", status="in_approval", current_node="node-me")
|
|
add_apply("a2", status="in_approval", current_node="node-me")
|
|
add_apply("a3", status="in_approval", current_node="node-other")
|
|
add_apply("a4", status="rejected", current_node="node-me")
|
|
add_apply("a5", status="draft", current_node=None)
|
|
db.commit()
|
|
|
|
monkeypatch.setattr(
|
|
"app.services.pl_menu_badge_service.apply_pl_scope",
|
|
lambda query, *_args, **_kwargs: query,
|
|
)
|
|
|
|
counts = build_menu_badge_counts(
|
|
db,
|
|
tenant_no="t1",
|
|
user=object(),
|
|
user_id="u-me",
|
|
menu_codes=[MENU_CODE_RECHARGE_APPROVAL],
|
|
)
|
|
assert counts[MENU_CODE_RECHARGE_APPROVAL] == 2
|