From 9cccaa6cfc6ad309c11c4f7f68009b2a43c92800 Mon Sep 17 00:00:00 2001 From: Hermes CI Fix Date: Mon, 31 Aug 2026 18:28:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(budget):=20=E5=B9=B4=E5=BA=A6=E5=88=86?= =?UTF-8?q?=E8=A7=A3400=E6=8F=90=E7=A4=BA=E4=BC=98=E5=8C=96=E2=80=94?= =?UTF-8?q?=E2=80=94=E5=90=AB=E5=8F=AF=E7=94=A8=E5=B9=B4=E4=BB=BD+?= =?UTF-8?q?=E5=8F=8C=E8=B7=AF=E5=BE=84=E5=BC=95=E5=AF=BC=20(budget-decompo?= =?UTF-8?q?se-400-hint)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/budget.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/app/api/budget.py b/backend/app/api/budget.py index ad366ae7..1077eef1 100644 --- a/backend/app/api/budget.py +++ b/backend/app/api/budget.py @@ -220,7 +220,18 @@ def auto_decompose_budget( kpi_version_used[kid] = chosen.version if not kpi_annual: - raise HTTPException(400, "该年度没有可分解的预算,请先在预算执行中录入年度预算") + # 查询该企业有哪些年份有年度预算行(供提示) + from sqlalchemy import distinct + avail_years = [r[0] for r in db.query(distinct(BudgetPlan.budget_year)).filter( + BudgetPlan.entity_id == entity_id, + BudgetPlan.period.like("%-00"), + BudgetPlan.status == "active", + ).order_by(BudgetPlan.budget_year).all()] + hint = f"该年度({year})没有年度预算总额(period=YYYY-00)" + if avail_years: + hint += f";现有年度数据年份:{', '.join(str(y) for y in avail_years)}" + hint += "。请先在预算录入中填写该年度预算总额,或改用战略预算编制按地图录入;如需按已有月度数据反向生成请咨询管理员。" + raise HTTPException(400, hint) results = [] created_count = 0 @@ -293,7 +304,7 @@ def auto_decompose_budget( # ── 单KPI模式(原有逻辑)── if annual_budget is None: - raise HTTPException(400, "缺少必要参数: annual_budget") + raise HTTPException(400, "缺少必要参数: annual_budget(单KPI分解需传年度预算值)") kpi = db.query(KPIDefinition).filter(KPIDefinition.id == kpi_id).first() if not kpi: