feat(lme): 决策185-190落地——动态工料机现算、并集视野重组、同码异价拆行、子级改价收严

This commit is contained in:
lianjianwei2024
2026-10-24 23:42:44 +08:00
parent c0b01b15a8
commit ac28658889
13 changed files with 1275 additions and 135 deletions

View File

@@ -94,15 +94,17 @@ def test_groups_unify_levels():
g = g[0]
proj = [r for r in g["rows"] if r["lvl"] == "proj"]
uws = [r for r in g["rows"] if r["lvl"] == "uw"]
assert {r["code"] for r in proj} == {K, P}
assert proj == [] # 决策 186 v3:弹框并集视野,项目级不进组
assert {r["code"] for r in uws} == {K, P, V15, V1}
krow = [r for r in uws if r["code"] == K][0]
assert krow["units"] == 2 and sorted(krow["uw_ids"]) == [101, 102]
assert krow["qty"] == 110.0 # 50 + 60
v15row = [r for r in uws if r["code"] == V15][0]
assert v15row["units"] == 2 and v15row["ntp"] == 126.96 # 2 条取低(126.96/130.0)
# 决策 189:同码不同价按价拆行——V15@126.96(uw101) 与 V15@130.0(uw102) 各一条
v15rows = [r for r in uws if r["code"] == V15]
assert len(v15rows) == 2 and all(r["units"] == 1 for r in v15rows)
assert sorted(r["ntp"] for r in v15rows) == [126.96, 130.0]
assert not any(x["name"] == "II级钢筋混凝土管 D800" for x in d["groups"]) # 单码不成组
assert g["rows"][0]["def"] is True and g["rows"][0]["code"] == K # 默认勾编码最短
assert g["rows"][0]["def"] is True and g["rows"][0]["code"] == P # 默认勾编码最短(P 17290070 < K 17290080;决策 186 并集视野)
def test_merge_v2_unify_and_no_code_edit():
@@ -121,9 +123,9 @@ def test_merge_v2_unify_and_no_code_edit():
# ③ 项目级隐藏
assert sc.execute("SELECT COALESCE(x_merged_hide,0) FROM s_lme_proj WHERE id=2").fetchone()[0] == 1
# ④ 全单位只显示保留码:无跳过——单位同时持有保留码与变体码时为同码双行(镜像源文件多行现实)
assert _uw_codes(sc, 101) == sorted([K, K, D800])
assert _uw_codes(sc, 102) == [K, K, K]
assert _uw_codes(sc, 103) == [K]
assert _uw_codes(sc, 101) == sorted([K, K, D800, '00010003']) # 决策 186 定稿:骨架组映射源(00010003)单位级缺失→新增
assert sorted(_uw_codes(sc, 102)) == sorted([K, K, K, '00010003']) # 决策 186 定稿:映射源新增
assert sorted(_uw_codes(sc, 103)) == sorted([K, '00010003']) # 决策 186 定稿:映射源新增
# ⑦ 三价同步(主人定「三价要同步更新」):换码的变体行三价=保留行三价,不留新旧两价并存
# uw101 K×2 + uw102 K×3 + uw103 K×1 = 6 行,全部 58.88/0/58.88
ntps = sorted(x["ntp"] for x in sc.execute(
@@ -163,17 +165,21 @@ def test_merge_keep_uw_only_no_proj():
{"uw": 1, "code": P, "uw_ids": [102]},
{"uw": 1, "code": V1, "uw_ids": [103]}]}]})
assert r["ok"] is True
assert _uw_codes(sc, 101) == sorted([V15, V15, D800])
assert _uw_codes(sc, 102) == [V15, V15, V15] # 原 K/P/@15 三行全归保留码(无跳过)
assert _uw_codes(sc, 103) == [V15]
assert _uw_codes(sc, 101) == sorted([V15, V15, D800, '99990001']) # 决策 186 定稿:映射源新增
assert sorted(_uw_codes(sc, 102)) == sorted([V15, V15, V15, '99990001']) # 决策 186 定稿:映射源新增
assert sorted(_uw_codes(sc, 103)) == sorted([V15, '99990001']) # 决策 186 定稿:映射源新增
uw10 = sorted(x[0] for x in sc.execute("SELECT code FROM s_lme_uw WHERE session_id=? AND uw_id=101", (SID,)))
assert '99990001' in uw10 # 决策 186 定稿:单位级映射源缺失→新增
# 三价统一为替换三价(M=126.96):全部 V15 行 126.96
assert all(x["ntp"] == 126.96 for x in sc.execute(
"SELECT ntp FROM s_lme_uw WHERE session_id=? AND code=?", (SID, V15)))
# 项目级确保有一行 保留码/替换三价(新增行,数量=被隐藏项目行合计 628.396);旧行隐藏
prows = [tuple(x) for x in sc.execute(
"SELECT code, qty, ntp, COALESCE(x_merged_hide,0) FROM s_lme_proj WHERE session_id=? ORDER BY id", (SID,))]
# 决策 186 定稿「块=母行+Element+映射源」:99990001(63.0)是骨架组映射源——项目级原有行在,
# 不重复插入;单位级(uw10)原无 → 新增一行(值取项目级现值;价格空=没算留空)
assert prows == [(K, 11.286, 58.88, 1), (P, 617.11, 126.96, 1),
(D800, 5.0, 90.0, 0), (V15, 628.396, 126.96, 0)]
(D800, 5.0, 90.0, 0), (V15, 628.396, 126.96, 0), ('99990001', 63.0, None, 0)]
# D800 完好
assert sc.execute("SELECT name FROM s_lme_proj WHERE id=3").fetchone()[0] == "II级钢筋混凝土管 D800"
rm = json.loads(sc.execute("SELECT v FROM s_settings WHERE scope='session:1' AND k='recode_map'").fetchone()[0])