feat(costreview): 新增清单库与项目目录管理并修复采纳定额单价回填及换行实体转义

This commit is contained in:
lianjianwei2024
2026-11-05 07:09:18 +08:00
parent 449d6d18ba
commit e113eb0264
69 changed files with 1487 additions and 39434 deletions

View File

@@ -270,6 +270,17 @@ def _child_block_html(txt, rows):
return "".join(sep_e + _child_node(ktmpl, c, q) for (c, q) in rows)
def _adopt_totals(frag, sm):
"""决策 273:单价行 Total 按 Name 匹配回填——一致=外部该行 Total;不一致=空串(留空)。
只动骨架已有的 UnitPriceCalculationOfItem 自闭合行(卡槽在才写)。"""
def _f(m):
a = dict(re.findall(r'(\w+)="([^"]*)"', m.group(1)))
nm = (a.get("Name") or "").strip()
v = sm.get(nm)
return _attr_set(m.group(0), "Total", "" if v is None else v)
return re.sub(r'<UnitPriceCalculationOfItem\b([^>]*?)/>', _f, frag)
def _zero_results(frag):
"""决策 106:克隆模板 innards 时把「结果值」属性清零——金额/数量是别人清单算出来的,
带过来就是脏数据;公式(QtyFormula/Express 文本)、费率(Rate)、结构属性原样保留,
@@ -376,6 +387,21 @@ def _norm_xml(n, lres, template=None, bill_qty=None):
pre, post = _zero_results(pre), _zero_results(post)
pre = re.sub(r'<ExpressElement\b[^>]*/>', '', pre)
post = re.sub(r'<ExpressElement\b[^>]*/>', '', post)
# 决策 273(2026-11-04 主人定):采纳定额的单价行 Total 按 Name 匹配外部——
# x_side(采纳时构造:同区模板行组+Total 按 Name 匹配外部,一致=外部值/不一致留空)
# 有值时回填 Total 覆盖清零;无 x_side 维持清零现状(106 口径不动)。
_sm = {}
if n.get("x_side"):
try:
for _rec in json.loads(n["x_side"]):
if _rec.get("tag") == "UnitPriceCalculationOfItem":
_a = _rec.get("attrs") or {}
_sm[(_a.get("Name") or "").strip()] = _a.get("Total")
except Exception:
_sm = {}
if _sm:
pre = _adopt_totals(pre, _sm)
post = _adopt_totals(post, _sm)
# 换算调整记录(补记十三):先剥掉模板的记录(那是模板定额的历史),再按本定额
# 会话携带的 x_adjust 重写——采纳定额的调整工艺(GConvInfo 标准换算/R*2,J*2/送桩
# 材料含量…)跟历史项目走,主人定「有信息就要搬」。行形态照模板首行克隆。

View File

@@ -413,7 +413,10 @@ def serialize(el, depth=0, ind=" ", keep_values=False, first=True, note_fn=No
pad = "" if first else "\n" + ind * depth
if keep_values:
from xml.sax.saxutils import escape
attrs = "".join(' %s="%s"' % (k, escape(str(v), {'"': "&quot;"}))
# 决策 263 补记(2026-11-04 主人报「项目特征导出后不点开换行乱」):
# 属性值里的字面 LF 在 XML 解析时按规范归一成空格——必须写 &#10; 实体才能保住换行
# (老引擎外科手术保留原 &#10; 实体无此问题;v2 全量序列化必须显式转)
attrs = "".join(' %s="%s"' % (k, escape(str(v), {'"': "&quot;"}).replace("\n", "&#10;"))
for k, v in el.attrib.items())
else:
attrs = "".join(' %s=""' % k for k, _ in el.attrib.items())