From a48a116e066add113b33554a085998ceea7cc57d Mon Sep 17 00:00:00 2001 From: wecom-fullstack Date: Tue, 6 Oct 2026 23:36:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(dupont):=20insight.detail=20=E5=8F=99?= =?UTF-8?q?=E8=BF=B0=E6=AE=B5=E5=AD=97=E9=9D=A2=20None=20=E6=94=B6?= =?UTF-8?q?=E5=8F=A3=EF=BC=88=E8=A1=A8=E7=8E=B0=E5=B1=82=20=5Ffmt=5Fval?= =?UTF-8?q?=EF=BC=8C=E4=BB=85=E6=96=87=E6=A1=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恒等式叙述段 5 处裸 f-string 插值(三因子 value / ROE / identity.diff)改走 _fmt_val: None → 「-」(与同段四列 _fmt 同族),有值原样输出(不经 :.2f,保证有值路径逐字节不变) - 结构化字段 roe / factors[*].value / identity.diff 仍为 null;check_identity 语义、dupont_basis.py 未改 - 基线 origin/main acf179a;本单零生产写(不推远端/不同步部署树/不重启/不连库) --- backend/app/api/reports.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/app/api/reports.py b/backend/app/api/reports.py index d736f80c..eebd254c 100644 --- a/backend/app/api/reports.py +++ b/backend/app/api/reports.py @@ -2418,15 +2418,20 @@ def get_dupont_analysis( # 存量/流量缺失时 raw 值为 None(如博海存量仅到区间外)⇒ 显式「-」,不得 None 格式化 return "-" if v is None else f"{v:.2f}" + def _fmt_val(v): + # 叙述段(恒等式三因子 / ROE / 偏差)表现层口径:缺失同族显式「-」; + # 有值时**原样输出**(不经 :.2f,保证有值路径逐字节不变)。 + return "-" if v is None else v + detail = (f"{label}口径(流量累计 {win['period_start']}~{win['period_end']}," f"存量{'平均' if cur['basis'] == 'average' else '期末回落'}" f"{',年化 ×12/' + str(win['months']) if annualize else ',非年化'}):" f"净利润 {_fmt(cur['raw']['net_profit'])}万 / 营业收入 {_fmt(cur['raw']['revenue'])}万 / " f"平均总资产 {_fmt(cur['raw']['total_assets'])}万 / 平均净资产 {_fmt(cur['raw']['equity'])}万;" - f"ROE = {factors['net_profit_margin']['value']}% × {factors['asset_turnover']['value']} × " - f"{factors['equity_multiplier']['value']} = {None if roe_exact is None else round(roe_exact, 2)}%" + f"ROE = {_fmt_val(factors['net_profit_margin']['value'])}% × {_fmt_val(factors['asset_turnover']['value'])} × " + f"{_fmt_val(factors['equity_multiplier']['value'])} = {_fmt_val(None if roe_exact is None else round(roe_exact, 2))}%" f"(恒等式 {'通过' if identity.get('status') == 'pass' else identity.get('status')}," - f"偏差 {identity.get('diff')} ≤ 容差 {identity.get('tolerance')})") + f"偏差 {_fmt_val(identity.get('diff'))} ≤ 容差 {identity.get('tolerance')})") if cur["basis_fallback"]: detail += f"|⚠️ {cur['basis_fallback_reason']}(basis_fallback=true)"