Files
pricing_review/CostReview/app/tests/test_lme_uw_card.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

68 lines
3.4 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 -*-
"""原数据·单位工程级工料机汇总防回归(决策 41,2026-10-11 主人定)。
口径:优先直读本单位工程自己的工料机汇总节点(s_lme_uw / lme_uw,解析时按 uw 归属
原样入库)——名称/规格/总数量/单价=源文件原样,返回 src='summary';老会话/老批次没有
这张表的数据 → 回退"清单→定额→消耗量"归集口径(src='agg'),行为与从前一致。
"""
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"))
sys.path.insert(0, os.path.join(os.path.dirname(_HERE), "server"))
import api_server as srv # noqa: E402
def _mk_sess(with_summary):
sc = sqlite3.connect(":memory:")
sc.row_factory = sqlite3.Row
c = sc.cursor()
c.execute("CREATE TABLE sessions(id INTEGER PRIMARY KEY, name TEXT, src_name TEXT)")
c.execute("""CREATE TABLE s_unit_works(id INTEGER PRIMARY KEY, session_id INT,
section_id INT, Number TEXT, Name TEXT, Total REAL, Specialty TEXT)""")
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 REAL, taxp_org REAL, taxp_expr REAL, x_flags TEXT)""")
c.execute("""CREATE TABLE s_lmes(id INTEGER PRIMARY KEY, session_id INT,
Number TEXT, Name TEXT, Specification TEXT, Unit TEXT, Kind INT,
NoTaxPrice REAL, TaxPrice REAL)""")
c.execute("""CREATE TABLE s_bills(id INTEGER PRIMARY KEY, session_id INT, uw_id INT,
Number TEXT)""")
c.execute("""CREATE TABLE s_norms(id INTEGER PRIMARY KEY, session_id INT, bill_id INT)""")
c.execute("""CREATE TABLE s_norm_res(id INTEGER PRIMARY KEY, norm_id INT,
res_code TEXT, qty REAL)""")
c.execute("INSERT INTO sessions VALUES(1,'工程甲','H_甲.cos4')")
c.execute("INSERT INTO s_unit_works VALUES(10, 1, NULL, 'UW-1', '土建单位工程', 100, '建筑')")
if with_summary:
# 源文件汇总节点原样:总数量 50.5825(归集 SUM 只会算出别的数)
c.execute("""INSERT INTO s_lme_uw(session_id, uw_id, code, name, spec, unit, kind,
qty, ntp, taxrate, taxp)
VALUES(1, 10, '05010002', '普通硅酸盐水泥', 'P.O42.5', 'kg', 2,
50.5825, 0.38, NULL, 0.4104)""")
else:
c.execute("INSERT INTO s_lmes VALUES(1, 1, '05010002', '普通硅酸盐水泥', '', 'kg', 2, 0.38, 0.4104)")
c.execute("INSERT INTO s_bills VALUES(1, 1, 10, 'B1')")
c.execute("INSERT INTO s_norms VALUES(1, 1, 1)")
c.execute("INSERT INTO s_norm_res VALUES(1, 1, '05010002', 33.5)")
sc.commit()
return sc
def test_summary_source_preferred():
sc = _mk_sess(with_summary=True)
d = srv._raw_uw(sc, srv.TBL["session"], 10, "lme")
assert d["src"] == "summary"
r = d["rows"][0]
assert r[0] == "05010002" and r[1] == "普通硅酸盐水泥" and r[5] == 50.5825 # 总数量=源文件原样
assert d["uw"]["Name"] == "土建单位工程"
def test_agg_fallback_without_summary():
sc = _mk_sess(with_summary=False)
d = srv._raw_uw(sc, srv.TBL["session"], 10, "lme")
assert d["src"] == "agg"
assert d["rows"][0][0] == "05010002" and d["rows"][0][5] == 33.5 # 归集 SUM(qty)