feat(export): 恢复旧导出引擎并加固换行与舍入、新增采纳来源溯源与项目目录排序
This commit is contained in:
@@ -98,39 +98,29 @@ def test_rule_registry():
|
||||
|
||||
|
||||
def test_lme_summary_two_shapes():
|
||||
"""工料机汇总行两种形态(普通行 / 带台班组成的块行)各按自己的样板输出——
|
||||
不能只用一个样板:否则另一形态的列被丢掉(2026-11-03 主人实测)。"""
|
||||
import json as _json
|
||||
host = ET.fromstring(
|
||||
"<UnitWorks>"
|
||||
'<LabourMaterialsEquipmentsMachinesSummary Number="" Name="" ExtraA=""/>'
|
||||
'<LabourMaterialsEquipmentsMachinesSummary Number="" Name="" ExtraB="">'
|
||||
'<LabourMaterialsEquipmentsMachinesElement Number="" Quantity=""/>'
|
||||
"</LabourMaterialsEquipmentsMachinesSummary>"
|
||||
"</UnitWorks>")
|
||||
rows = [
|
||||
["A1", "普通行", "", "个", 1, 2, 10, 0, 10, None, None, None, None,
|
||||
_json.dumps({"ExtraA": "va"})],
|
||||
["B1", "组合行", "", "台班", 7, 1, 20, 0, 20, None, None, None, None,
|
||||
_json.dumps({"ExtraB": "vb"})],
|
||||
]
|
||||
ev._emit_sums(host, rows, {"B1": [("C1", 1.5)]})
|
||||
sums = [c for c in host if c.tag == "LabourMaterialsEquipmentsMachinesSummary"]
|
||||
assert len(sums) == 2
|
||||
by = {s.get("Number"): s for s in sums}
|
||||
assert by["A1"].get("ExtraA") == "va" and len(by["A1"]) == 0
|
||||
assert by["B1"].get("ExtraB") == "vb"
|
||||
kids = [c for c in by["B1"] if c.tag == "LabourMaterialsEquipmentsMachinesElement"]
|
||||
assert len(kids) == 1 and kids[0].get("Number") == "C1"
|
||||
assert kids[0].get("Quantity") == "1.500000"
|
||||
# 两种形态在序列化上必须分开:普通行自闭合、组合行带闭合标签
|
||||
import skeleton_engine as _se
|
||||
txt = _se.serialize(host, 0, " ", keep_values=True)
|
||||
line_a = next(ln for ln in txt.splitlines() if 'Number="A1"' in ln)
|
||||
line_b = next(ln for ln in txt.splitlines() if 'Number="B1"' in ln)
|
||||
assert line_a.rstrip().endswith("/>"), line_a
|
||||
assert line_b.rstrip().endswith(">"), line_b
|
||||
assert "</LabourMaterialsEquipmentsMachinesSummary>" in txt
|
||||
"""工料机汇总行两种形态(普通自闭合行 / 带台班组成的块行)各按自己的样板输出——
|
||||
恢复旧引擎(2026-11-05 主人拍板)后等价通道=_summary_node 模板克隆:
|
||||
children_html 空=自闭合、非空=成对块;不能混用样板:否则另一形态的列被丢掉(主人实测)。"""
|
||||
import export_cos as _xc
|
||||
_T = "LabourMaterialsEquipmentsMachinesSummary"
|
||||
_L = "LabourMaterialsEquipmentsMachinesElement"
|
||||
tmpl_a = '<%s Number="X" Name="n" ExtraA=""/>' % _T
|
||||
tmpl_b = ('<%s Number="X" Name="n" ExtraB=""><%s Number="C0" Quantity="1"/></%s>'
|
||||
% (_T, _L, _T))
|
||||
a = _xc._summary_node(("A1", "普通行", "", "个", 1, 2, 10, 0, 10), tmpl_a)
|
||||
b = _xc._summary_node(("B1", "组合行", "", "台班", 7, 1, 20, 0, 20), tmpl_b,
|
||||
children_html='<%s Number="C1" Quantity="1.500000"/>' % _L)
|
||||
# 行独有扩展列经合并回写通道(_lme_apply_price._flags,决策 259 全采)落行:
|
||||
a = _xc._lme_apply_price(a, {"NoTaxPrice": 10, "TaxPrice": 0, "_flags": {"ExtraA": "va"}})
|
||||
b = _xc._lme_apply_price(b, {"NoTaxPrice": 20, "TaxPrice": 0, "_flags": {"ExtraB": "vb"}})
|
||||
# 普通行:自闭合、模板独有列 ExtraA 保留
|
||||
assert a.startswith("<%s " % _T) and a.endswith("/>"), a
|
||||
assert 'Number="A1"' in a and 'ExtraA="va"' in a, a
|
||||
# 组合行:成对块、模板独有列 ExtraB 保留、子级照 children_html
|
||||
assert ("<%s " % _T) in b and b.endswith("</%s>" % _T), b
|
||||
assert 'Number="B1"' in b and 'ExtraB="vb"' in b, b
|
||||
assert '<%s Number="C1" Quantity="1.500000"/>' % _L in b, b
|
||||
# 两种形态在产物上必须分开:普通行自闭合、组合行带闭合标签(上面两段形态断言)
|
||||
|
||||
|
||||
def test_blankpkg_endpoint(server):
|
||||
@@ -241,22 +231,13 @@ def test_unit_side_rows_exported(server):
|
||||
"district": H.META["district"], "period_from": H.PERIOD_202607,
|
||||
"period_to": H.PERIOD_202607, "file_kind": 1}
|
||||
sid = post(server, "/api/audit", dict(audit, path=H.twin_file(server, hp)))["session_id"]
|
||||
# 用独立骨架库(只放本件骨架)直接走 export_v2,避免并行用例的骨架库干扰
|
||||
hpath = str(server["root"] / ("side_hist_%s.db" % proj[-6:]))
|
||||
hic = sqlite3.connect(hpath)
|
||||
hic.row_factory = sqlite3.Row
|
||||
try:
|
||||
assert cs.seed_frame(hic, hp, "非数据层骨架-" + proj[-6:])
|
||||
sc = sqlite3.connect(server["sessdb"])
|
||||
sc.row_factory = sqlite3.Row
|
||||
try:
|
||||
data, _fn, err = ev.export_v2(hic, sc, sid, "cos4", src_path=hp)
|
||||
finally:
|
||||
sc.close()
|
||||
finally:
|
||||
hic.close()
|
||||
assert err is None, err
|
||||
z = zipfile.ZipFile(io.BytesIO(data))
|
||||
# 恢复旧引擎(2026-11-05 主人拍板):走 /api/session/export——非数据层=源件原样保留
|
||||
resp = server["client"].get("/api/session/export",
|
||||
params={"session_id": sid, "name": proj,
|
||||
"province": H.META["province"], "city": H.META["city"],
|
||||
"period_from": H.PERIOD_202607})
|
||||
assert resp.headers["content-type"].startswith("application/zip"), resp.text[:300]
|
||||
z = zipfile.ZipFile(io.BytesIO(resp.content))
|
||||
unit = z.read([n for n in z.namelist() if n != "Project.xml"][0]).decode("utf-8")
|
||||
assert unit.count("<AddiCost") == 2, unit[:800]
|
||||
assert 'Name="附加费甲"' in unit and 'Name="附加费乙"' in unit
|
||||
|
||||
Reference in New Issue
Block a user