chore: tk 全量提交(新增 formats 模块与界面体检测试包,更新核心/UI/测试/文档)
This commit is contained in:
@@ -94,6 +94,94 @@ def make_cos4(path, proj_name, bills, lmes=(), build_unit="测试建设单位",
|
||||
return path
|
||||
|
||||
|
||||
def make_swt(path, proj_name, units, total=None, tenderee="测试建设单位"):
|
||||
"""构造最小可解析的 .SWT(深圳市工程造价数据交换标准 SJG77-2020)。
|
||||
|
||||
units: [{
|
||||
"id","name","total","a","b","c","d","e","b1", # 单位工程与 Summary 五项
|
||||
"bills":[{"code","name","feature","unit","qty","rate",
|
||||
"norms":[{"code","name","unit","qty","rate","res":[(rid, usage)]}]}],
|
||||
"resources":[{"id","code","name","spec","unit","rate","qty","kind",
|
||||
"subs":[(rid, usage)]}],
|
||||
"measures":[{"code","name","unit","total","children":[...]}] # 可嵌套
|
||||
}]
|
||||
⚠️ ResourceID 在 SWT 里是单位工程内部编号:不同 unit 可用同一个 id 指不同编码,
|
||||
这正是回归要覆盖的重号场景。
|
||||
"""
|
||||
def attrs(d):
|
||||
return " ".join("%s=%s" % (k, quoteattr(str(v))) for k, v in d.items() if v is not None)
|
||||
|
||||
def measure_xml(m):
|
||||
return '<MeasureItem %s>%s</MeasureItem>' % (
|
||||
attrs({"MeasureItemID": m.get("id", ""), "Code": m["code"], "Name": m["name"],
|
||||
"Unit": m.get("unit", "项"), "Total": m.get("total", 0), "Sequence": 1}),
|
||||
"".join(measure_xml(c) for c in m.get("children", [])))
|
||||
|
||||
ups = []
|
||||
for u in units:
|
||||
resources = "".join(
|
||||
'<ResourceItem %s>%s</ResourceItem>' % (
|
||||
attrs({"ResourceID": r["id"], "Code": r["code"], "Name": r["name"],
|
||||
"Spec": r.get("spec", ""), "Unit": r.get("unit", ""),
|
||||
"Rate": r.get("rate", 0), "Quantity": r.get("qty", 0), "Total": 0,
|
||||
"CostKind": r.get("kind", 2), "Provider": 0,
|
||||
"StandardCode": r["code"], "NormLibrary": ""}),
|
||||
"".join('<ResourceUsage ResourceID=%s Usage=%s/>' % (
|
||||
quoteattr(str(rid)), quoteattr(str(usage))) for rid, usage in r.get("subs", [])))
|
||||
for r in u.get("resources", []))
|
||||
bills = "".join(
|
||||
'<BQItem %s><Norms>%s</Norms></BQItem>' % (
|
||||
attrs({"BQItemID": b.get("id", ""), "Code": b["code"], "Name": b["name"],
|
||||
"Feature": b.get("feature", ""), "Unit": b["unit"], "Quantity": b["qty"],
|
||||
"Rate": b["rate"], "Total": round(float(b["qty"]) * float(b["rate"]), 2),
|
||||
"Sequence": 1}),
|
||||
"".join(
|
||||
'<NormItem %s>%s</NormItem>' % (
|
||||
attrs({"NormItemID": n.get("id", ""), "Code": n["code"], "Name": n["name"],
|
||||
"Unit": n["unit"], "Quantity": n["qty"], "Rate": n["rate"],
|
||||
"Total": round(float(n["qty"]) * float(n["rate"]), 2), "Sequence": 1}),
|
||||
"".join('<NormResUsageItem ResourceID=%s Usage=%s/>' % (
|
||||
quoteattr(str(rid)), quoteattr(str(usage)))
|
||||
for rid, usage in n.get("res", [])))
|
||||
for n in b.get("norms", [])))
|
||||
for b in u.get("bills", []))
|
||||
measures = "".join(measure_xml(m) for m in u.get("measures", []))
|
||||
summary = "".join(
|
||||
'<SummaryItem CostCode=%s CostKind=%s Name=%s Total=%s/>' % (
|
||||
quoteattr(code), quoteattr(str(kind)), quoteattr(name),
|
||||
quoteattr(str(u.get(key, 0))))
|
||||
for code, kind, name, key in (("A", 8, "分部分项工程", "a"), ("B", 15, "措施项目", "b"),
|
||||
("B1", 22, "安全文明施工费", "b1"),
|
||||
("C", 16, "其他项目", "c"), ("D", 21, "增值税", "d"),
|
||||
("E", 24, "工程造价", "e")))
|
||||
ups.append(
|
||||
'<UnitProject ProjectID=%s Name=%s Total=%s>'
|
||||
'<Summary>%s</Summary>'
|
||||
'<BQTable><BQTitle BQTitleID="1" Name="整个项目">%s</BQTitle></BQTable>'
|
||||
'%s'
|
||||
'<Resource>%s</Resource>'
|
||||
'</UnitProject>' % (
|
||||
quoteattr(str(u["id"])), quoteattr(u["name"]), quoteattr(str(u.get("total", 0))),
|
||||
summary, bills,
|
||||
('<MeasureTable><MeasureTitle MeasureTitleID="2" Name="措施项目">%s'
|
||||
'</MeasureTitle></MeasureTable>' % measures) if measures else "",
|
||||
resources))
|
||||
if total is None:
|
||||
total = sum(float(u.get("total", 0)) for u in units)
|
||||
xml = ('<?xml version="1.0" encoding="utf-8"?>\r\n'
|
||||
'<ConstructProject Code="001" Name=%s Tenderee=%s Standard="深圳市工程造价数据交换标准" '
|
||||
'FileType="2" Version="SJG77-2020" TaxModel="1">'
|
||||
'<TenderInfo Total=%s/>'
|
||||
'<ProjectAddInfo><ProjectAddInfoItem Name="编制人" Value="测试"/></ProjectAddInfo>'
|
||||
'<SingleProject ProjectID="1" Name="单项一" Total=%s>%s</SingleProject>'
|
||||
'</ConstructProject>' % (
|
||||
quoteattr(proj_name), quoteattr(tenderee), quoteattr(str(total)),
|
||||
quoteattr(str(total)), "".join(ups)))
|
||||
with open(path, "w", encoding="utf-8", newline="") as f:
|
||||
f.write(xml)
|
||||
return str(path)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ 服务夹具
|
||||
@pytest.fixture(scope="session")
|
||||
def server(tmp_path_factory):
|
||||
|
||||
Reference in New Issue
Block a user