- 对账检查页新增容差列:人数严格相等(容差 0)、金额 0.01、比率 0.0001, 状态公式改为 ABS(差异)<=容差,不再统一使用 0.01 - 自定义列不再标注“需业务验收/无服务器参考”:新增 to_decimal 白名单表达式 解释器(仅遍历 metric/number/四则节点,不执行代码)在服务器端用 Decimal 计算参考值,缺失指标或除零返回 None(对应 #N/A → 无参考) - 参数页写明对账规则与“容差调整需财务负责人批准” - 测试:求值器黄金样例(大数/抵消/极小值/除零/缺失/多层表达式)、 分指标容差列、自定义列 Decimal 参考与缺失场景、全指标覆盖检查; LibreOffice 用例验证全部对账行重算后为“通过/无参考”(本机跳过)
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from io import BytesIO
|
|
|
|
import pytest
|
|
from openpyxl import load_workbook
|
|
|
|
from finance.exporting import build_formula_workbook
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_reconcile_status_guards_non_numeric_difference(workspace):
|
|
ds, member, *_ = workspace
|
|
ds.periods = ["2025-08"]
|
|
ds.save(update_fields=["periods"])
|
|
output = BytesIO()
|
|
build_formula_workbook(
|
|
ds,
|
|
member,
|
|
{"start": "2026-08", "end": "2026-08", "comparison": "yoy", "group": "department"},
|
|
output,
|
|
)
|
|
workbook = load_workbook(BytesIO(output.getvalue()), data_only=False)
|
|
status_cells = [row[7] for row in workbook["对账检查"].iter_rows(min_row=2)]
|
|
formulas = [
|
|
cell.value for cell in status_cells if isinstance(cell.value, str) and cell.value.startswith("=IF(D")
|
|
]
|
|
assert formulas
|
|
assert all("ISNUMBER(F" in formula for formula in formulas)
|
|
assert all('"通过"' in formula for formula in formulas)
|
|
# 容差列独立成列,状态按容差比较而不是统一 0.01
|
|
assert all(row[6].value is not None for row in workbook["对账检查"].iter_rows(min_row=2))
|