Files
pricing_review/AdminCost/_std_schema.py

157 lines
7.2 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.
"""按《建设工程造价数据交换标准》给各层级节点建属性列。
「工程费用」层按两家造价软件的一致做法不建(项目直接进入建筑安装工程费)。
列 = 标准属性:中文列名 + 英文属性名(std_name)+ 数据类型 + 是否必填。
同时在「字段设置」里给该节点建同名同分组的字段,保证界面与标准一一对应。
"""
import sys
import app
# (英文属性名, 中文列名, 类型, 必填, 说明)
TABLES = {
11: (
"ConstructionProject",
[
("Number", "项目编号", "String", 1, "建设项目的唯一编号"),
("Name", "项目名称", "String", 1, "建设项目名称"),
("FileKind", "文件类型", "Integer", 1, "1投资估算/2设计概算/3施工图预算/4工程量清单/5最高投标限价/6投标报价/7签约合同价/8结算价"),
("ValuationMethod", "计价类别", "Integer", 1, "1清单计价/2定额计价/3全费用清单计价"),
("TaxModel", "计税模式", "Integer", 1, "1一般计税法/2简易计税法/3营业税计税法"),
("StandardName", "标准名称", "String", 1, "数据交换标准名称"),
("StandardNumber", "标准编号", "String", 1, "数据交换标准编号"),
("Scale", "建设规模", "Double", 1, "只填数字部分,如 20000"),
("ScaleUnit", "建设规模单位", "String", 1, "如 ㎡、km"),
("MaterialPriceDate", "材料价格时间", "String", 1, "精确到月,YYYY-MM"),
("Explains", "总说明", "String", 0, "项目总说明"),
],
),
13: (
"ProjectInstallationWorkCost",
[
("Name", "工程名称", "String", 1, "建筑安装工程费名称"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("Code", "费用代号", "String", 0, "费用代号"),
("Remark", "备注", "String", 0, "备注"),
],
),
14: (
"SectionalWorks",
[
("Number", "工程编号", "String", 0, "单项工程编号"),
("Name", "工程名称", "String", 1, "单项工程名称"),
("Segment", "标段名称", "String", 0, "所属标段"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Specialty", "专业类别", "String", 1, "见标准表 4.2.1-2,如 01 房屋建筑与装饰工程"),
("Scale", "建设规模", "Double", 1, "只填数字部分"),
("ScaleUnit", "建设规模单位", "String", 1, "如 ㎡、km"),
("Ratios", "占项目费用比率(%)", "Double", 0, "占整个项目费用比率"),
("Code", "费用代号", "String", 0, "费用代号"),
("Remark", "备注", "String", 0, "备注"),
],
),
15: (
"UnitWorks",
[
("Number", "工程编号", "String", 1, "单位工程编号"),
("Name", "工程名称", "String", 1, "单位工程名称"),
("Segment", "标段名称", "String", 0, "所属标段"),
("ValuationMethod", "计价类别", "Integer", 1, "1清单计价/2定额计价"),
("TaxModel", "计税模式", "Integer", 1, "1一般计税法/2简易计税法/3营业税计税法"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Specialty", "专业类别", "String", 1, "见标准表 4.2.1-2"),
("Purposes", "工程用途", "String", 0, "工程用途"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("ScaleUnit", "建设规模单位", "String", 0, "如 ㎡、km"),
("BillDataBase", "清单库", "String", 0, "所用清单库"),
("NormDataBase", "定额库", "String", 0, "所用定额库"),
("Code", "费用代号", "String", 0, "费用代号"),
("Explains", "总说明", "String", 0, "单位工程总说明"),
("Remark", "备注", "String", 0, "备注"),
],
),
}
# 子表节点对应的标准元素名
SUB_ELEMENTS = {
2: "LabourMaterialsEquipmentsMachinesSummary",
8: "LabourMaterialsEquipmentsMachinesElement",
10: "UnitWorksSummary",
3: "DivisionalAndElementalWorks",
4: "Norm",
5: "Preliminaries",
6: "Norm",
}
def main(apply=False):
app.init_db()
conn = app.connect()
try:
changed = 0
for tab_id, (element, items) in TABLES.items():
tab = conn.execute("SELECT id, name FROM tabs WHERE id = ?", (tab_id,)).fetchone()
if tab is None:
print("跳过:标签 %s 不存在" % tab_id)
continue
conn.execute("UPDATE tabs SET element = ? WHERE id = ?", (element, tab_id))
gid = conn.execute(
"SELECT id FROM field_groups WHERE tab_id = ?", (tab_id,)
).fetchone()
if gid is None:
print("跳过:%s 没有字段分组" % tab["name"])
continue
gid = gid["id"]
order = conn.execute(
"SELECT COALESCE(MAX(sort_order), 0) AS o FROM columns WHERE tab_id = ?",
(tab_id,),
).fetchone()["o"]
for std, cn, typ, req, note in items:
order += 1
fid = conn.execute(
"SELECT id FROM fields WHERE group_id = ? AND name = ?", (gid, cn)
).fetchone()
if fid is None:
cur = conn.execute(
"INSERT INTO fields(name, note, is_value, sort_order, created_at,"
" group_id) VALUES(?,?,0,?,?,?)",
(cn, note, order, app.now_str(), gid),
)
fid = cur.lastrowid
col = conn.execute(
"SELECT id FROM columns WHERE tab_id = ? AND name = ?", (tab_id, cn)
).fetchone()
if col is None:
conn.execute(
"INSERT INTO columns(tab_id, name, kind, sort_order, width,"
" created_at, std_name, std_type, required, std_note)"
" VALUES(?,?,?,?,0,?,?,?,?,?)",
(tab_id, cn, "custom", order, app.now_str(), std, typ, req, note),
)
changed += 1
else:
conn.execute(
"UPDATE columns SET std_name = ?, std_type = ?, required = ?,"
" std_note = ? WHERE id = ?",
(std, typ, req, note, col["id"]),
)
print("%-12s 建列 %d 条(元素 %s)" % (tab["name"], len(items), element))
for tab_id, element in SUB_ELEMENTS.items():
conn.execute("UPDATE tabs SET element = ? WHERE id = ?", (element, tab_id))
app.sync_field_groups(conn)
if apply:
conn.commit()
print("已提交")
else:
conn.rollback()
print("预演结束(未提交)")
print("新增列数:", changed)
finally:
conn.close()
if __name__ == "__main__":
main(apply="--apply" in sys.argv)