diff --git a/backend/app/api/pl/vehicle_recharge.py b/backend/app/api/pl/vehicle_recharge.py index a351f4ac1..8a6790ad0 100644 --- a/backend/app/api/pl/vehicle_recharge.py +++ b/backend/app/api/pl/vehicle_recharge.py @@ -39,7 +39,7 @@ record_router = APIRouter(prefix="/vehicle-recharge-record", tags=["运输计划 RECHARGE_TYPE_LABELS = {"etc": "ETC", "fuel": "油卡", "shanxia": "山峡", "bailian": "百链"} RECHARGE_APPLY_STATUS_LABELS = { "draft": "草稿", - "pending": "待发放", + "pending": "发放中", "in_approval": "审批中", "rejected": "已驳回", "disbursed": "已发放", diff --git a/backend/app/services/pl_vehicle_recharge_service.py b/backend/app/services/pl_vehicle_recharge_service.py index 8a46005bd..bb05d95bc 100644 --- a/backend/app/services/pl_vehicle_recharge_service.py +++ b/backend/app/services/pl_vehicle_recharge_service.py @@ -481,7 +481,7 @@ def _resolve_apply_for_record( detail="审批中的申请请在「ETC/油卡充值审批」中完成发放登记", ) if apply.status != "pending": - raise HTTPException(status_code=400, detail="仅待发放申请可关联") + raise HTTPException(status_code=400, detail="仅发放中申请可关联") existing = ( db.query(PlVehicleRechargeRecord) .filter( @@ -1133,7 +1133,7 @@ def update_record( ), nodes[-1] if nodes else None, ) - old_apply.status = "in_approval" + old_apply.status = "pending" old_apply.current_node = disburse.id if disburse else None else: old_apply.status = "pending" @@ -1202,7 +1202,7 @@ def delete_records( ), nodes[-1] if nodes else None, ) - apply.status = "in_approval" + apply.status = "pending" apply.current_node = disburse.id if disburse else None else: apply.status = "pending" diff --git a/backend/tests/test_pl_vehicle_recharge_workflow.py b/backend/tests/test_pl_vehicle_recharge_workflow.py index 5faea9867..356800047 100644 --- a/backend/tests/test_pl_vehicle_recharge_workflow.py +++ b/backend/tests/test_pl_vehicle_recharge_workflow.py @@ -615,3 +615,49 @@ def test_withdraw_rejects_non_in_approval(monkeypatch): with pytest.raises(HTTPException) as ei: svc.withdraw_apply(db, "t1", _user("u-applicant"), "a-wd3") assert ei.value.status_code == 400 + + +def test_delete_record_with_workflow_reverts_to_pending(monkeypatch): + from app.services import pl_vehicle_recharge_service as svc + + db = _make_session() + _seed_vehicle(db) + wf_id, _gm, node_fin = _seed_workflow(db) + db.add( + PlVehicleRechargeApply( + id="apply-1", + apply_no="ETC2026092601", + license_plate="鄂A00001", + recharge_type="etc", + apply_date=date(2026, 9, 26), + applicant_id="u-applicant", + status="disbursed", + wf_id=wf_id, + current_node=None, + approval_round=1, + tenant_no="t1", + create_by="u-applicant", + create_dept_id="d1", + ) + ) + db.add( + PlVehicleRechargeRecord( + id="rec-1", + recharge_order_no="RO1", + recharge_date=date(2026, 9, 26), + recharge_type="etc", + amount=Decimal("10.00"), + apply_id="apply-1", + license_plate="鄂A00001", + tenant_no="t1", + create_by="u-fin", + create_dept_id="d1", + del_flag=0, + ) + ) + db.commit() + _patch_scope(monkeypatch, svc) + svc.delete_records(db, "t1", _user("u-fin", "财务"), ["rec-1"]) + apply = db.query(PlVehicleRechargeApply).filter_by(id="apply-1").one() + assert apply.status == "pending" + assert apply.current_node == node_fin