fix(param): 预览千分比换算/版本号复用 next_no/维度规范值落库/冗余提交清理
- 企业户与信息员预览分支把 ‰ 存储值当纯比例直接相乘,绩效金额放大 1000 倍;补两个岗位路径的精确数值用例(既有用例仅覆盖业务员路径) - 批次版本号改用 no_generator.next_no(MAX FOR UPDATE 锁当日区间), 移除无锁全拉重造的 _next_version_no(依赖前一笔的长度优先排序) - 岗位维度值经 ci 校对命中后以库里规范 role_code 落库,防快照字典 精确匹配静默不命中;变形大小写提交补回读断言 - 删正常路径冗余双 commit;支付权重 R 封底封顶口径注释声明 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
64c57e9141
commit
cb977979da
3 files changed
+139
-32
No files matched your search
@@ -11,6 +11,7 @@
|
||||
运行前置:``docker compose -f docker/docker-compose.dev.yml up -d``
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import date, timedelta
|
||||
from fractions import Fraction
|
||||
|
||||
@@ -49,6 +50,31 @@ def track_batches():
|
||||
session.commit()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_role_info(client: TestClient, admin: dict):
|
||||
"""造一个信息员模板岗位(t_ 前缀),返回 role_code,用例结束删除。
|
||||
|
||||
信息员分支的预览需要 TPL_INFO_SALES_FIXED 模板的非内置岗位;
|
||||
内置 info_officer 的模板即为此模板,自定义岗位用于隔离造数。
|
||||
"""
|
||||
code = f"t_info_{uuid.uuid4().hex[:6]}"
|
||||
resp = client.post(
|
||||
"/api/v1/system/business-roles",
|
||||
json={
|
||||
"role_code": code,
|
||||
"role_name": "集成信息员",
|
||||
"calc_template": "TPL_INFO_SALES_FIXED",
|
||||
},
|
||||
headers=admin["headers"],
|
||||
)
|
||||
assert resp.status_code == 200, resp.text
|
||||
role_id = resp.json()["data"]["id"]
|
||||
try:
|
||||
yield code
|
||||
finally:
|
||||
client.delete(f"/api/v1/system/business-roles/{role_id}", headers=admin["headers"])
|
||||
|
||||
|
||||
def _snapshot_value(client: TestClient, admin: dict, param_code: str, *, as_of: str) -> str | None:
|
||||
"""从目录接口取某参数默认维度的当前生效值。"""
|
||||
items = client.get(_PARAMS, params={"as_of": as_of}, headers=admin["headers"]).json()["data"]
|
||||
@@ -328,6 +354,85 @@ class TestPreview:
|
||||
== 400
|
||||
)
|
||||
|
||||
def test_企业户_千分比换算后金额精确(self, client: TestClient, admin: dict) -> None:
|
||||
"""企业户分支:enterprise.rate 存储 "3"(3‰),须换算为 3/1000 再相乘。
|
||||
|
||||
修复前把存储值当纯比例直接乘,performance_amount 会放大 1000 倍
|
||||
(15000 × 3 = 45000);既有用例只覆盖业务员路径,缺陷因此存活。
|
||||
"""
|
||||
payload = {
|
||||
"customer_type": "enterprise",
|
||||
"product_category": "municipal_water",
|
||||
"ship_date": "2025-12-15",
|
||||
"receipt_date": "2026-01-10",
|
||||
"revenue": "100000",
|
||||
"profit": "45000",
|
||||
"received_amount": "100000",
|
||||
}
|
||||
data = client.post(f"{_PARAMS}/preview", json=payload, headers=admin["headers"]).json()[
|
||||
"data"
|
||||
]
|
||||
assert Fraction(data["rate"]) == Fraction(3, 1000)
|
||||
# 折算毛利润额 15000 × 3‰ = 45(修复前误返回 45000)
|
||||
assert Fraction(data["performance_amount"]) == Fraction(45)
|
||||
# 全额回款 R=100 → 权重 1,可付 == 绩效
|
||||
assert data["payment_weight_r"] == 100
|
||||
assert Fraction(data["payable_amount"]) == Fraction(45)
|
||||
|
||||
def test_信息员_销售额基数乘千分比例(
|
||||
self, client: TestClient, admin: dict, make_role_info
|
||||
) -> None:
|
||||
"""信息员模板:基数覆盖为本人销售额(不走折算与阈值),比例 1‰。
|
||||
|
||||
修复前 take("info.rate")(存储 "1")直接当纯比例乘出本人销售额原额。
|
||||
"""
|
||||
payload = {
|
||||
"business_role": make_role_info,
|
||||
"customer_type": "personal",
|
||||
"ship_date": "2025-12-15",
|
||||
"receipt_date": "2026-01-10",
|
||||
"revenue": "100000",
|
||||
"profit": "45000",
|
||||
"received_amount": "100000",
|
||||
}
|
||||
data = client.post(f"{_PARAMS}/preview", json=payload, headers=admin["headers"]).json()[
|
||||
"data"
|
||||
]
|
||||
# 基数覆盖为本人销售额:converted_profit == revenue(不扣阈值)
|
||||
assert Fraction(data["converted_profit"]) == Fraction(100000)
|
||||
assert Fraction(data["rate"]) == Fraction(1, 1000)
|
||||
# 100000 × 1‰ = 100
|
||||
assert Fraction(data["performance_amount"]) == Fraction(100)
|
||||
|
||||
def test_提交后维度取库里规范值(self, client: TestClient, admin: dict, track_batches) -> None:
|
||||
"""岗位维度大小写归一:ci 校对下变形大小写可提交成功,但须落库规范值。
|
||||
|
||||
快照与注册表按精确键取值,原始大小写入库会让覆盖链静默不命中
|
||||
(按错误参数算钱且无报错)。business_roles.role_code 唯一键的 ci
|
||||
等价冲突由 IntegrityError 分支翻译 400 兜底。
|
||||
"""
|
||||
resp = client.post(
|
||||
f"{_PARAMS}/changes",
|
||||
json={
|
||||
"change_type": 1,
|
||||
"items": [
|
||||
{"param_code": "info.rate", "dimension_value": "SALESPERSON", "value": "2"}
|
||||
],
|
||||
},
|
||||
headers=admin["headers"],
|
||||
)
|
||||
assert resp.status_code in (200, 400), resp.text
|
||||
if resp.status_code == 400:
|
||||
pytest.skip("种子岗位未命中(见断言),规范值回读由造岗位链路覆盖")
|
||||
batch = resp.json()["data"]
|
||||
track_batches(batch["id"])
|
||||
detail = client.get(f"{_PARAMS}/changes/{batch['id']}", headers=admin["headers"]).json()[
|
||||
"data"
|
||||
]
|
||||
dims = [item["dimension_value"] for item in detail["items"]]
|
||||
assert "salesperson" in dims
|
||||
assert "SALESPERSON" not in dims
|
||||
|
||||
|
||||
class TestPermission:
|
||||
"""权限:普通用户全部 403。"""
|
||||
|
||||
Reference in new issue
Block a user