feat(export): 采纳定额携带含量算式与换算调整,屏蔽金额汇总行改价同步
This commit is contained in:
@@ -85,11 +85,12 @@ def test_appended_norm_keeps_innards():
|
||||
"""采纳定额追加进原有清单:innards 一并克隆(此前裸 Norm 同样过不了结构关)。"""
|
||||
out = xcos._norm_xml(NEW_NORM, [("00010010", 594.0)], xcos._full_norm_block(RICH_BILL))
|
||||
norm = _parse(out)
|
||||
assert [c.tag for c in norm] == ["ExpressElement", "ManageFees",
|
||||
# 补记二十一:采纳定额不带数量算式行(Express 大于 Quantity,易达会按算式显示代号/方括号)
|
||||
assert [c.tag for c in norm] == ["ManageFees",
|
||||
"LabourMaterialsEquipmentsMachinesElement",
|
||||
"UnitPriceCalculationOfItem", "UnitPriceCalculationOfItem"]
|
||||
assert all(c.get("Total") == "0" for c in norm.findall("UnitPriceCalculationOfItem"))
|
||||
assert norm.find("ExpressElement").get("Express") == "" # 表达式文本清空(别人的公式带 QGCL 但量是别人的)
|
||||
assert norm.findall("ExpressElement") == [] # 补记二十一:采纳定额不带数量算式行(易达才显示纯数字,不带方括号)
|
||||
assert norm.get("Remark") == "" # 决策 101 口径不变
|
||||
|
||||
|
||||
@@ -248,6 +249,177 @@ def test_new_bill_top_anchor_position(server):
|
||||
assert txt.index('Name="顶部新增清单"') < txt.index('Number="B001"'), "新增清单应在第一条源清单之前"
|
||||
|
||||
|
||||
def test_amount_aggregate_row_price_never_synced():
|
||||
"""决策 106 补记九:广联达文件的「人工费」类汇总行是金额汇总行(数量=金额合计、
|
||||
单价恒 1、单位=元)。会话里合并改价把它的单价改成资源口径(如人工 500 元/工日)
|
||||
后,导出同步不得回写——原文件 数量×500 会让 Glodon 人工费爆炸外溢(样例工程实测)。"""
|
||||
txt = ('<ConstructionProject>'
|
||||
'<LabourMaterialsEquipmentsMachinesSummary Number="00010010" Name="人工费" Unit="元"'
|
||||
' Quantity="4142082.6" NoTaxPrice="1" TaxRate="0" TaxPrice="1"/>'
|
||||
'<LabourMaterialsEquipmentsMachinesSummary Number="990101015" Name="履带式推土机" Unit="台班"'
|
||||
' Quantity="6.1" NoTaxPrice="1039.8" TaxRate="9.48" TaxPrice="1138.37"/>'
|
||||
'</ConstructionProject>')
|
||||
sync = [("00010010", "人工费", "", "元", 500.0, 0.0, 500.0),
|
||||
("990101015", "履带式推土机", "", "台班", 1232.54, 0.0, 1232.54)]
|
||||
out = xcos.transform_project(txt, [], [], sync_rows=sync)
|
||||
agg = re.search(r'<LabourMaterialsEquipmentsMachinesSummary Number="00010010"[^>]*', out).group(0)
|
||||
assert 'NoTaxPrice="1"' in agg and 'TaxPrice="1"' in agg # 金额汇总行价格不动
|
||||
mac = re.search(r'<LabourMaterialsEquipmentsMachinesSummary Number="990101015"[^>]*', out).group(0)
|
||||
assert 'NoTaxPrice="1232.54"' in mac # 正常资源行照常回写
|
||||
assert xcos._is_amount_aggregate(
|
||||
'<LabourMaterialsEquipmentsMachinesSummary Number="X" Unit="元" NoTaxPrice="1"/>')
|
||||
assert not xcos._is_amount_aggregate(
|
||||
'<LabourMaterialsEquipmentsMachinesSummary Number="X" Unit="台班" NoTaxPrice="1039.8"/>')
|
||||
|
||||
|
||||
def test_adoption_carries_express_adjustment(server):
|
||||
"""决策 106 补记十二:定额换算调整式(含量 Express,如人工费 *1.2)跟历史项目走——
|
||||
导入捕获入库 → 采纳携带 → 导出按算式原样填写(此前只存数值,调整信息丢失)。"""
|
||||
import hashlib
|
||||
import sqlite3
|
||||
import uuid
|
||||
proj = "调整式工程-" + uuid.uuid4().hex[:6]
|
||||
bills = [("010101001001", "挖单独土方", "1、x", "m3", 10000, 126.17)]
|
||||
p = H.make_cos4(str(server["src_dir"] / ("expr_%s_raw.cos4" % proj[-6:])), proj, bills)
|
||||
# 给夹具的定额工料机行补上换算算式(模拟广联达原生 Express)
|
||||
z = _zipfile.ZipFile(p) if False else zipfile.ZipFile(p)
|
||||
buf = io.BytesIO()
|
||||
with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as zo:
|
||||
for nm in z.namelist():
|
||||
d = z.read(nm)
|
||||
if nm.lower() != "project.xml":
|
||||
d = d.replace(b'Quantity="1.5"/>', b'Quantity="1.5" Express="1.5*1.2"/>')
|
||||
d = d.replace(b'<Norm ', b'<Norm NormIdentity="TEST 1 2018" ')
|
||||
zo.writestr(nm, d)
|
||||
raw = buf.getvalue()
|
||||
hp = os.path.join(str(server["root"]), "CostReview", "data", "source_files",
|
||||
"%s_expr.cos4" % hashlib.sha256(raw).hexdigest())
|
||||
with open(hp, "wb") as f:
|
||||
f.write(raw)
|
||||
imp = post(server, "/api/admin/import", dict(H.META, path=hp, name=proj))
|
||||
assert imp["ok"] is True, imp
|
||||
hc = sqlite3.connect(server["db"])
|
||||
got = hc.execute("SELECT express FROM norm_res WHERE express IS NOT NULL").fetchall()
|
||||
hc.close()
|
||||
assert got and got[0][0] == "1.5*1.2", got[:3] # 导入捕获算式
|
||||
audit = {"name": proj, "province": H.META["province"], "city": H.META["city"],
|
||||
"district": H.META["district"], "period_from": H.PERIOD_202607,
|
||||
"period_to": H.PERIOD_202607, "file_kind": 1}
|
||||
resp = post(server, "/api/audit", dict(audit, path=hp))
|
||||
assert resp.get("session_id"), resp
|
||||
sid = resp["session_id"]
|
||||
rows = get(server, "/api/session/rows", session_id=sid, type="bill")["rows"]
|
||||
bill_id = [r[0] for r in rows if r[1] == bills[0][0]][0]
|
||||
src_id = sqlite3.connect(server["db"]).execute(
|
||||
"SELECT id FROM bills WHERE Number=?", (bills[0][0],)).fetchone()[0]
|
||||
r = post(server, "/api/session/bill/adopt", {"session_id": sid, "bill_id": bill_id,
|
||||
"src_bill_id": src_id})
|
||||
assert r["ok"] is True, r
|
||||
se = sqlite3.connect(server["sessdb"])
|
||||
got = se.execute("SELECT express FROM s_norm_res WHERE norm_id IN "
|
||||
"(SELECT id FROM s_norms WHERE bill_id=? AND x_adopt=1)", (bill_id,)).fetchall()
|
||||
se.close()
|
||||
assert got and got[0][0] == "1.5*1.2", got[:3] # 采纳携带
|
||||
zf = _export_zip(server, sid)
|
||||
txt = "".join(zf.read(n).decode("utf-8", errors="replace") for n in zf.namelist()
|
||||
if n.lower() != "project.xml")
|
||||
import re as _re
|
||||
mm = _re.search(r'<Norm Number="N-1".{0,600}?</Norm>', txt, _re.S)
|
||||
print('ADOPTED NORM BLOCK:', mm.group(0)[:600] if mm else '(N-1 不在导出中)')
|
||||
print('txt has N-1:', 'N-1' in txt, '| txt len:', len(txt))
|
||||
assert 'Express="1.5*1.2"' in txt # 导出按历史调整式填写
|
||||
|
||||
|
||||
|
||||
def test_resource_pseudo_norm_skipped_on_import(server):
|
||||
"""决策 106 补记十四:广联达把清单级资源构成行(人工费等,编码=纯数字工料机码、
|
||||
单位=元)也写成 <Norm> 元素——不是定额,导入即滤掉(此前被采纳当定额带进
|
||||
工作台=人工费外溢实测);真定额与调整记录不受影响。"""
|
||||
import hashlib
|
||||
import sqlite3
|
||||
import uuid
|
||||
proj = "伪定额过滤工程-" + uuid.uuid4().hex[:6]
|
||||
bills = [("010101001001", "挖单独土方", "1、x", "m3", 10000, 126.17)]
|
||||
p = H.make_cos4(str(server["src_dir"] / ("pseudo_%s_raw.cos4" % proj[-6:])), proj, bills)
|
||||
z = zipfile.ZipFile(p)
|
||||
buf = io.BytesIO()
|
||||
with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as zo:
|
||||
for nm in z.namelist():
|
||||
d = z.read(nm)
|
||||
if nm.lower() != "project.xml":
|
||||
pseudo = ('<Norm Number="00010010" Name="人工费" Unit="元" Quantity="89.1513"'
|
||||
' Price="1.2" Total="106.98" IsNorm="true" Type="1" CalculationKind="1"'
|
||||
' CostKind="1" EfficiencyKind="2" IncFeeKind="2" Specialty="1"'
|
||||
' NormIdentity="TEST 1 2018" Remark=""/>').encode("utf-8")
|
||||
d = d.replace(b'</Norm></WorkElement>', b'</Norm>' + pseudo + b'</WorkElement>')
|
||||
zo.writestr(nm, d)
|
||||
raw = buf.getvalue()
|
||||
hp = os.path.join(str(server["root"]), "CostReview", "data", "source_files",
|
||||
"%s_pseudo.cos4" % hashlib.sha256(raw).hexdigest())
|
||||
with open(hp, "wb") as f:
|
||||
f.write(raw)
|
||||
imp = post(server, "/api/admin/import", dict(H.META, path=hp, name=proj))
|
||||
assert imp["ok"] is True, imp
|
||||
hc = sqlite3.connect(server["db"])
|
||||
n = hc.execute("SELECT COUNT(*) FROM norms WHERE Number='00010010'").fetchone()[0]
|
||||
hc.close()
|
||||
assert n == 0, n # 伪定额不落批次库
|
||||
audit = {"name": proj, "province": H.META["province"], "city": H.META["city"],
|
||||
"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=hp))["session_id"]
|
||||
sc = sqlite3.connect(server["sessdb"])
|
||||
n2 = sc.execute("SELECT COUNT(*) FROM s_norms WHERE Number='00010010'").fetchone()[0]
|
||||
n3 = sc.execute("SELECT COUNT(*) FROM s_norms").fetchone()[0]
|
||||
sc.close()
|
||||
assert n2 == 0 and n3 >= 1, (n2, n3) # 工作台也不出现(外溢源头掐断)
|
||||
|
||||
|
||||
def test_edited_totals_follow_qty_times_price(server):
|
||||
"""决策 106 补记十六(主人定):清单/定额 合价 = 工程量×单价——
|
||||
改工程量后(工作台保存时 + 导出兜底)合价跟着走;数值相同不产生字节改动。"""
|
||||
import hashlib
|
||||
import sqlite3
|
||||
import uuid
|
||||
proj = "合价口径工程-" + uuid.uuid4().hex[:6]
|
||||
bills = [("B001", "挖单独土方", "1、x", "m3", 10, 500)]
|
||||
p = H.make_cos4(str(server["src_dir"] / ("total_%s_raw.cos4" % proj[-6:])), proj, bills)
|
||||
raw = open(p, "rb").read()
|
||||
hp = os.path.join(str(server["root"]), "CostReview", "data", "source_files",
|
||||
"%s_total.cos4" % hashlib.sha256(raw).hexdigest())
|
||||
with open(hp, "wb") as f:
|
||||
f.write(raw)
|
||||
imp = post(server, "/api/admin/import", dict(H.META, path=hp, name=proj))
|
||||
assert imp["ok"] is True, imp
|
||||
audit = {"name": proj, "province": H.META["province"], "city": H.META["city"],
|
||||
"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=hp))["session_id"]
|
||||
rows = get(server, "/api/session/rows", session_id=sid, type="bill")["rows"]
|
||||
bill_id = [r[0] for r in rows if r[1] == "B001"][0]
|
||||
norm_id = sqlite3.connect(server["sessdb"]).execute(
|
||||
"SELECT id FROM s_norms WHERE bill_id=?", (bill_id,)).fetchone()[0]
|
||||
# 改清单工程量 10→20:合价 = 20×500
|
||||
r = post(server, "/api/session/bill/op", {"session_id": sid, "op": "edit",
|
||||
"bill_id": bill_id, "fields": {"Quantity": "20"}})
|
||||
assert r["ok"] is True, r
|
||||
tb = sqlite3.connect(server["sessdb"]).execute(
|
||||
"SELECT Total FROM s_bills WHERE id=?", (bill_id,)).fetchone()[0]
|
||||
assert abs(tb - 10000) < 0.01, tb # 工作台保存即同步
|
||||
# 改定额工程量 10→15(数字):合价 = 15×80
|
||||
r = post(server, "/api/session/norm/op", {"session_id": sid, "norm_id": norm_id,
|
||||
"fields": {"Quantity": "15"}})
|
||||
assert r["ok"] is True, r
|
||||
tn = sqlite3.connect(server["sessdb"]).execute(
|
||||
"SELECT Total FROM s_norms WHERE id=?", (norm_id,)).fetchone()[0]
|
||||
assert abs(tn - 1200) < 0.01, tn # 15×80
|
||||
zf = _export_zip(server, sid)
|
||||
txt = "".join(zf.read(n).decode("utf-8", errors="replace") for n in zf.namelist()
|
||||
if n.lower() != "project.xml")
|
||||
assert 'Total="10000.0"' in txt, "清单合价应=20×500"
|
||||
assert 'Total="1200.00"' in txt, "定额合价应=15×80"
|
||||
|
||||
|
||||
def _export_zip(server, sid):
|
||||
resp = server["client"].get("/api/session/export", params={"session_id": sid})
|
||||
if not resp.headers["content-type"].startswith("application/zip"):
|
||||
|
||||
Reference in New Issue
Block a user