fix(profit-caliber): 博海口径 §4-1/§4-2/§4-5 落地 —— 固定成本仅借方 + 6403 进变动 + 财务收益单列 + 批次备注
ci/woodpecker/push/main Pipeline was successful
ci/woodpecker/push/main Pipeline was successful
ASK-20261014-04(任总 2026-10-14 11:20「放行4」)批后口径: - §4-1 博海固定成本弃净额:6601/6602/6603 仅借方(133.98 万,2026-01..09);2026-03 单月由 -9.02 万转正; 6603 贷方(现金折扣收益 64.40 万)改 finance_income_terms 单列备查,不进固定成本/末行/勾稽。 - §4-2 博海变动成本追加 6403 营业税金及附加(530.17 万)。 - §4-3/§4-4 维持现行(酣客收入/边际贡献基数不动)。 - §4-5 管理利润表页加「数据批次/导入时刻」纯展示备注(import_logs)。 - 口径唯一源仍为 bep_caliber.ENTITY_CALIBERS;报表/卡面/派生器一律经 fixed_cost_spec() 解析(读口写口一致)。
This commit is contained in:
@@ -13,7 +13,7 @@ from app.utils.voucher_guard import apply_voucher_guard
|
||||
from app.utils.threshold_parser import eval_threshold
|
||||
from app.utils.alert_entity_scope import month_period_clause
|
||||
# BEP 实体口径单一事实源(2026-10-03 扩面:酣客 entity1 / 博海 entity2 同表驱动派生器与卡面)
|
||||
from app.utils.bep_caliber import CLOSING_SUMMARY_LIKE, caliber_or_none
|
||||
from app.utils.bep_caliber import CLOSING_SUMMARY_LIKE, caliber_or_none, fixed_cost_spec
|
||||
# 「实测区 / 预估区」分区口径单一事实源(财务裁定 2026-10-02,任总「把 H2 预测行与实际分离」)
|
||||
# —— 预估行(data_status='estimated' 或 source_type='forecast')禁进实测汇总 / 趋势序列 /
|
||||
# 预警依据;仅 include_forecast=true 时以独立字段(forecast_value / is_forecast)单列返回。
|
||||
@@ -74,7 +74,7 @@ BEP_DEP_SUBJECT = "560213"
|
||||
|
||||
def _bep_sum_field(db, entity_id: int, period_from: str, period_to: str,
|
||||
field: str, subject_filter=None, *, exclude_closing: bool = False,
|
||||
subject_filters=None) -> float:
|
||||
subject_filters=None, terms=None) -> float:
|
||||
"""聚合 voucher_details 金额(元),subject_filter: ('eq', code) / ('like', prefix)
|
||||
|
||||
field="net" = 借−贷 净额(口径4:费用/损益一律净额)。
|
||||
@@ -82,9 +82,20 @@ def _bep_sum_field(db, entity_id: int, period_from: str, period_to: str,
|
||||
—— 见 /srv/hermes/wisdom/_decisions/cma-expense-profit-net-caliber-20261002.md。
|
||||
exclude_closing(2026-10-03):该账套结转腿未标 carry_forward 时(博海:全账套 cf 恒 0),
|
||||
须按 summary NOT LIKE '%结转%' 显式剔除,否则已结账期间净额恒 0。
|
||||
subject_filters:多条 OR(固定成本 6601+6602+6603)。
|
||||
subject_filters:多条 OR(固定成本前缀口径;酣客 5601/5602/5603 借−贷净额)。
|
||||
terms(2026-10-15,ASK-20261014-04 §4-1):**带号科目项** [(sign, code, field), ...]
|
||||
—— `bep_caliber.fixed_cost_spec()` 解析出的博海形态(6601/6602/6603 **仅借方**);
|
||||
每项独立聚合后按符号相加,行域(账套/cf=0/剔结转腿/剔作废)与上面完全一致。
|
||||
作废/撤单标记过滤(2026-09-14 收口): 已作废凭证不参与 BEP 均值。
|
||||
"""
|
||||
if terms:
|
||||
total = 0.0
|
||||
for sign, code, tfield in terms:
|
||||
total += (1.0 if sign == "+" else -1.0) * _bep_sum_field(
|
||||
db, entity_id, period_from, period_to, tfield,
|
||||
("like", str(code)[:-1]) if str(code).endswith("%") else ("eq", code),
|
||||
exclude_closing=exclude_closing)
|
||||
return total
|
||||
expr = (VoucherDetail.debit_amount - VoucherDetail.credit_amount
|
||||
if field == "net" else getattr(VoucherDetail, field))
|
||||
q = db.query(func.sum(expr)).filter(
|
||||
@@ -115,12 +126,21 @@ def _bep_sum_field(db, entity_id: int, period_from: str, period_to: str,
|
||||
|
||||
|
||||
def _bep_inputs(db, entity_id: int, cal: dict, period_from: str, period: str, months: int) -> dict:
|
||||
"""卡面展示用输入(万元/百分比)——按实体口径现算,与派生器同源同式。"""
|
||||
"""卡面展示用输入(万元/百分比)——按实体口径现算,与派生器同源同式。
|
||||
|
||||
固定成本(admin):经 `bep_caliber.fixed_cost_spec()` **唯一解析口**取科目构成 ——
|
||||
e1 酣客 = 5601%/5602%/5603% 借−贷净额;e2 博海 = 6601/6602/6603 **仅借方**(§4-1 批后口径)。
|
||||
"""
|
||||
fix_mode, fix_spec = fixed_cost_spec(cal)
|
||||
sales = _bep_sum_field(db, entity_id, period_from, period, cal["revenue_field"],
|
||||
cal["revenue_filter"], exclude_closing=cal["exclude_closing"]) / 10000.0
|
||||
admin = _bep_sum_field(db, entity_id, period_from, period, "net",
|
||||
subject_filters=cal["fixed_filters"],
|
||||
exclude_closing=cal["exclude_closing"]) / 10000.0
|
||||
if fix_mode == "terms":
|
||||
admin = _bep_sum_field(db, entity_id, period_from, period, "net",
|
||||
terms=fix_spec, exclude_closing=cal["exclude_closing"]) / 10000.0
|
||||
else:
|
||||
admin = _bep_sum_field(db, entity_id, period_from, period, "net",
|
||||
subject_filters=fix_spec,
|
||||
exclude_closing=cal["exclude_closing"]) / 10000.0
|
||||
dep = _bep_sum_field(db, entity_id, period_from, period, cal["dep_field"],
|
||||
cal["dep_filter"], exclude_closing=cal["exclude_closing"]) / 10000.0
|
||||
return {
|
||||
|
||||
@@ -29,7 +29,7 @@ from app.utils.dupont_basis import (
|
||||
)
|
||||
from app.utils.voucher_guard import apply_voucher_guard
|
||||
from app.utils.profit_lines import (BOTTOM_LABEL, UNIT, build_items, compute_lines,
|
||||
prev_period_of, reconcile)
|
||||
import_batches, prev_period_of, reconcile)
|
||||
from app.services import report_reclass
|
||||
from app.deps import get_entity_id, assert_entity_slug_scope, resolve_session_slug
|
||||
import logging
|
||||
@@ -77,6 +77,8 @@ def get_profit_summary(
|
||||
"entity_id": entity_id,
|
||||
"unit": UNIT,
|
||||
"bottom_label": BOTTOM_LABEL,
|
||||
"desc": ("基于管理会计视角的利润结构分析:营业收入 → 变动成本 → 边际贡献 → 固定成本 → "
|
||||
f"{BOTTOM_LABEL}(真实科目取数,按账套口径现算)"),
|
||||
"source": "voucher_details 真实凭证明细发生额(按 entity 隔离;剔结转腿 + 作废/撤单行)",
|
||||
"available": cur["available"],
|
||||
"missing": cur["missing"],
|
||||
@@ -84,6 +86,10 @@ def get_profit_summary(
|
||||
"prev_missing": prev["missing"],
|
||||
"caliber": cur.get("caliber"),
|
||||
"items": build_items(cur, prev),
|
||||
# §4-1:财务收益(博海 6603 贷方现金折扣收益等)单列备查 —— 不进固定成本、不参与勾稽
|
||||
"finance_income": cur.get("finance_income"),
|
||||
# 4-5 备注(**纯展示**:数据批次 / 导入时刻,取 import_logs)—— 不参与任何计算
|
||||
"data_batches": import_batches(db, entity_id, period),
|
||||
"reconciliation": reconcile(values.get("revenue"), values.get("variable_cost"),
|
||||
values.get("fixed_cost"), values.get("result")),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user