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

82 lines
5.0 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 -*-
"""决策 220(2026-10-27 主人定):③「两级都没有→补来源行」时,带子级的母行**子级组成整套随行带入**
(来源 lme_res → 会话 s_lme_res);①②(本单位有/仅项目有)绝不动子级——
主人原话「只有新加入的带子级工料机,本项目完全没有,采纳才会补进来」。函数级直调 _adopt_summary_rows。"""
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_sc():
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_adopt_added INTEGER DEFAULT 0, x_merged_hide INTEGER DEFAULT 0, 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, x_adopt_added INTEGER DEFAULT 0, 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))""")
sc.commit()
return sc
def _mk_hc():
hc = sqlite3.connect(":memory:")
hc.row_factory = sqlite3.Row
c = hc.cursor()
c.execute("CREATE TABLE bills(id INTEGER PRIMARY KEY, batch_id INT, Number TEXT, Name TEXT)")
c.execute("""CREATE TABLE lmes(id INTEGER PRIMARY KEY, batch_id INT, Number TEXT, Name TEXT,
Specification TEXT, Unit TEXT, Kind REAL, Quantity REAL, TaxRate REAL,
NoTaxPrice REAL, TaxPrice REAL)""")
c.execute("""CREATE TABLE lme_res(id INTEGER PRIMARY KEY, batch_id INT, p_code TEXT,
res_code TEXT, qty REAL, seq INTEGER, name TEXT)""")
c.execute("INSERT INTO bills(id, batch_id, Number, Name) VALUES(900, 5, 'S1', '来源清单')")
# 两个来源工料机:M1=本项目完全没有的带子级母行(③+子级);M2=本项目已有同名规单(①/②,不动)
c.execute("INSERT INTO lmes(batch_id, Number, Name, Specification, Unit, NoTaxPrice, TaxPrice) "
"VALUES(5, 'M1', '灰浆搅拌机', '200L', '台班', 100.0, 100.0)")
c.execute("INSERT INTO lmes(batch_id, Number, Name, Specification, Unit, NoTaxPrice, TaxPrice) "
"VALUES(5, 'M2X', '电动夯实机', '20-62t·m', '台班', 50.0, 50.0)")
c.executemany("INSERT INTO lme_res(batch_id, p_code, res_code, qty, seq, name) VALUES(5,'M1',?,?,?,?)",
[("C1", 2.0, 1, "人工"), ("C2", 3.0, 2, "电")])
hc.commit()
return hc
def test_adopt_children_full_path():
sc, hc = _mk_sc(), _mk_hc()
hc.execute("CREATE TABLE norms(id INTEGER PRIMARY KEY, bill_id INT)")
hc.execute("CREATE TABLE norm_res(norm_id INT, res_code TEXT, qty REAL)")
hc.execute("INSERT INTO norms(id, bill_id) VALUES(10, 900)")
hc.executemany("INSERT INTO norm_res(norm_id, res_code, qty) VALUES(?,?,?)",
[(10, "M1", 0.5), (10, "M2X", 0.2)])
hc.commit()
# 本项目已有 M2 同名规单(项目级),自带子级
sc.execute("""INSERT INTO s_lme_proj(session_id, code, name, spec, unit, kind, qty, ntp, taxrate, taxp)
VALUES(1, 'M2P', '电动夯实机', '20-62t·m', '台班', 3, 1, 60, 0, 60)""")
sc.execute("INSERT INTO s_lme_res(session_id, p_code, res_code, qty, seq, name) VALUES(1,'M2P','OWN1',9,1,'本项目子级')")
sc.commit()
n, code_map = srv._adopt_summary_rows(sc, hc, 1, 101, 900)
# M1:③补两级 + 子级整套带入(决策 220)
m1 = sc.execute("SELECT ntp FROM s_lme_proj WHERE session_id=1 AND code='M1'").fetchone()
assert m1 and m1["ntp"] == 100.0
assert sc.execute("SELECT 1 FROM s_lme_uw WHERE session_id=1 AND uw_id=101 AND code='M1'").fetchone()
kids = [(r["res_code"], r["qty"]) for r in sc.execute(
"SELECT res_code, qty FROM s_lme_res WHERE session_id=1 AND p_code='M1' ORDER BY seq")]
assert kids == [("C1", 2.0), ("C2", 3.0)] # 来源子级整套进来
assert code_map.get("M1") == "M1"
# M2X:②按项目编码落地(M2P),两级零新增、子级**不动**(本项目子级 OWN1 唯一在场)
assert code_map.get("M2X") == "M2P"
assert sc.execute("SELECT COUNT(*) FROM s_lme_res WHERE session_id=1 AND p_code='M2P'").fetchone()[0] == 1
assert sc.execute("SELECT 1 FROM s_lme_res WHERE session_id=1 AND p_code='M2P' AND res_code='OWN1'").fetchone()