Files
pricing_review/CostReview/app/tests/test_lme_chain219.py
lianjianwei2024 78e58a40c7 feat(export): 决策263-266 单一骨架导出通路/数据全量入库/空骨架规则标注/导入按内容判族
- 决策 263:定额单价专题(三同合并全字段统一、原价三级链、LME Summary 26 属性收口、x_flags 采集、e2e 回归)
- 决策 264 补记五:原格式导出只保留骨架回灌一条通路;删除 export_cos.export_zip 旧引擎;新增 skeleton_engine(内容判族/唯一结构位/结构旁注/路径指纹);单位级/项目级非数据层 x_attr/x_side 采集与回灌;导出件成员名改 GBK 原始字节(_GbkZipInfo);后台「导出设置」导出空骨架(标注)
- 决策 265:导入按内容判族(zip 内含 ConstructProject→SWT 族,否则 COS 族;裸 XML 同),扩展名不参与拦截;api_scan 取消 EXT_OK 过滤
- 决策 266:结构位统一「自增区域/自增块/自增行」,取消「固定」;min_count(区域1/块行0),导出条数=max;区域数据0条保底1空壳;LME 汇总两形态(带组成闭合块/普通自闭合行)按行硬分派
- 前序未提交:HTML 导出整体移除(export_html.py 删除)、Excel 导出加序号列并移除说明页、.yhy 导入(import_yhy.py)
- 测试:367 passed / 3 skipped;新增 test_topic_price/test_yhy_import/test_import_suffix 等
2026-11-03 23:39:46 +08:00

101 lines
6.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""决策 219(2026-10-26 主人定):工料机取价链——单位级一码一行认第一行 + 项目级全字段三价一致才归并。
钉死五件事(样本对数法,数字全部取自会话75报障形态):
① 单位级取价:每单位工程每码认导入序**第一行**(同码不同价随便认一个);
② 项目级归并:全字段(名/规/单/类别)+三价一致的单位级行并一行、量=成员单位现算量之和;
③ 不一致独立:字段或三价不同 → 各自成行(机柜 两种规格两行);s_lme_proj 异类价(3.61)不再出现;
④ 兜底:单位级行缺价 → 项目级快照补;仅项目级有的码 → 独立成行(量=现算);
⑤ 单位级卡:本单位每码一行、量=本单位现算。
"""
import sqlite3
import sys, os
_HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(_HERE), "core"))
import dyn_lme as dyn # noqa: E402
def _mk():
sc = sqlite3.connect(":memory:")
sc.row_factory = sqlite3.Row
c = sc.cursor()
c.execute("""CREATE TABLE s_lme_proj(id INTEGER PRIMARY KEY, session_id INT, code TEXT,
name TEXT, spec TEXT, unit TEXT, kind INT, qty REAL,
ntp REAL, taxrate REAL, taxp REAL, x_merged_hide INTEGER DEFAULT 0,
x_remark TEXT, x_ntp0 REAL, x_rate0 REAL, x_taxp0 REAL, ntp_org REAL, ntp_expr TEXT, taxp_org REAL, taxp_expr TEXT, x_flags TEXT, x_org_ntp0 REAL, x_org_taxp0 REAL)""")
c.execute("""CREATE TABLE s_lme_uw(id INTEGER PRIMARY KEY, session_id INT, uw_id INT,
code TEXT, name TEXT, spec TEXT, unit TEXT, kind INT,
qty REAL, ntp REAL, taxrate REAL, taxp REAL, ntp_org REAL, ntp_expr TEXT, taxp_org REAL, taxp_expr TEXT, x_flags TEXT)""")
c.execute("""CREATE TABLE s_lme_res(id INTEGER PRIMARY KEY, session_id INT,
p_code TEXT, res_code TEXT, qty REAL, seq INTEGER, name TEXT)""")
c.execute("""CREATE TABLE s_settings(scope TEXT NOT NULL, k TEXT NOT NULL, v TEXT,
PRIMARY KEY(scope,k))""")
c.execute("CREATE TABLE s_bills(id INTEGER PRIMARY KEY, session_id INT, uw_id INT, Quantity REAL)")
c.execute("CREATE TABLE s_norms(id INTEGER PRIMARY KEY, bill_id INT, Quantity REAL, Unit TEXT)")
c.execute("CREATE TABLE s_norm_res(id INTEGER PRIMARY KEY, norm_id INT, res_code TEXT, qty REAL)")
# 单位级行(id 序=导入序)——101/102 各有电:101 认第一行 0.77(0.75 被随便认掉)
c.executemany("""INSERT INTO s_lme_uw(id, session_id, uw_id, code, name, spec, unit, kind,
qty, ntp, taxrate, taxp) VALUES(?,1,?,?,?,?,?,?,?,?,?,?)""",
[(1, 101, "E", "电", "", "度", 3, 1.0, 0.77, 0.0, 0.77),
(2, 101, "E", "电", "", "度", 3, 2.0, 0.75, 0.0, 0.75), # 同单位第二行 → 不认
(3, 102, "E", "电", "", "度", 3, 20.0, 0.77, 0.0, 0.77),
(4, 102, "G", "镀锌扁钢", "综合", "kg", 3, 5.0, 5.59, 0.0, 5.59),
(5, 101, "G", "镀锌扁钢", "综合", "kg", 3, 5.0, 5.59, 0.0, 5.59),
(6, 101, "M", "机柜", "", "个", 3, 1.0, 100.0, 0.0, 100.0),
(7, 101, "M", "机柜", "42U", "个", 3, 1.0, 100.0, 0.0, 100.0), # 同单位第二行 → 不认
(8, 102, "M", "机柜", "24U", "个", 3, 20.0, 100.0, 0.0, 100.0),
(9, 101, "P", "型钢", "", "kg", 3, 2.0, None, None, None)]) # 缺价 → 兜底项目级
# 项目级:E 是异类价 3.61(报障形态,不得再出现);Z 仅项目级有;P 供缺价兜底
c.executemany("""INSERT INTO s_lme_proj(id, session_id, code, name, spec, unit, kind,
qty, ntp, taxrate, taxp) VALUES(?,1,?,?,?,?,?,?,?,?,?)""",
[(901, "E", "电", "", "度", 3, 999.0, 3.61, 0.0, 0.0),
(902, "Z", "支架", "", "kg", 3, 0.0, 9.9, 0.0, 9.9),
(903, "P", "型钢", "", "kg", 3, 0.0, 2.0, 0.0, 2.0)])
# 现算链:101=3、102=20(E);G 101=5/102=5;M 101=1/102=20;Z 102=10;P 101=2
c.executemany("INSERT INTO s_bills(id, session_id, uw_id, Quantity) VALUES(?,1,?,?)",
[(1, 101, 1.0), (2, 101, 1.0), (3, 102, 1.0)])
c.executemany("INSERT INTO s_norms(id, bill_id, Quantity, Unit) VALUES(?,?,?,NULL)",
[(1, 1, 1.0), (2, 2, 1.0), (3, 3, 10.0)])
c.executemany("INSERT INTO s_norm_res(norm_id, res_code, qty) VALUES(?,?,?)",
[(1, "E", 3.0), (1, "G", 5.0), (1, "M", 1.0), (1, "P", 2.0),
(3, "E", 2.0), (3, "G", 0.5), (3, "M", 2.0), (3, "Z", 1.0)])
sc.commit()
return sc
def _by_code(rows):
return {(r[1], r[2], r[3]): r for r in rows}
def test_uw_first_row_and_merge_rules():
rows = dyn.dyn_rows(_mk(), 1, None)
d = _by_code(rows)
# ② 全一致 → 并一行,量=成员单位现算和(101:3 + 102:20),价=单位级 0.77(不是项目级异类 3.61)
e = d[("E", "电", "")]
assert (e[5], e[6], e[7], e[8]) == (23.0, 0.77, 0.0, 0.77)
g = d[("G", "镀锌扁钢", "综合")]
assert (g[5], g[6]) == (10.0, 5.59)
# ③ 字段不一致 → 各自独立两行(101 认无规格 1、102 是 24U 20)
m1 = d[("M", "机柜", "")]
m2 = d[("M", "机柜", "24U")]
assert m1[5] == 1.0 and m2[5] == 20.0
# ④ 兜底:P 单位级行缺价 → 项目级 2.0 补;Z 仅项目级有 → 独立成行(量=现算 10)
p = d[("P", "型钢", "")]
assert (p[5], p[6]) == (2.0, 2.0)
z = d[("Z", "支架", "")]
assert (z[5], z[6]) == (10.0, 9.9)
# 项目级 E 只有一行(0.75 与 3.61 都不出现在结果里)
assert len([r for r in rows if r[1] == "E"]) == 1
def test_uw_view_own_rows():
rows = dyn.dyn_uw_rows(_mk(), 1, 101)
d = {(r[0], r[1]): r for r in rows}
# ①⑤ 本单位每码一行:电认第一行 0.77(0.75 不认)、机柜认无规格;量为本单位现算
assert d[("E", "电")][5] == 3.0 and d[("E", "电")][6] == 0.77
assert ("M", "机柜") in d and d[("M", "机柜")][5] == 1.0
assert d[("P", "型钢")][6] == 2.0 # 缺价兜底
assert ("Z", "支架") not in d # 本单位表无行且无现算 → 不出