feat: 落地决策 209/211/213——临删联动与0量隐藏、历史检索硬过滤项单位与0价、附件列及只看未绑筛选
This commit is contained in:
@@ -3112,9 +3112,18 @@ def api_bill_op(sc, body):
|
||||
return {"ok": True, "sid": sid}
|
||||
if op == "tdel":
|
||||
sc.execute("UPDATE s_bills SET x_tdel=1 WHERE id=?", (bid,))
|
||||
# 决策 209(2026-10-26 主人定):临删清单=其下**全部定额**一起临删;临删定额才是单条
|
||||
sc.execute("UPDATE s_norms SET x_tdel=1 WHERE bill_id=?", (bid,))
|
||||
return {"ok": True, "sid": sid}
|
||||
if op == "untdel":
|
||||
sc.execute("UPDATE s_bills SET x_tdel=0 WHERE id=?", (bid,))
|
||||
# 决策 209:取消临删恢复定额——采纳过的清单只恢复采纳定额(其下原定额的临删来自
|
||||
# 采纳替换,**只有取消采纳才恢复**,同 api_bill_unadopt / api_norm_op unadopt);
|
||||
# 无采纳的清单全部恢复。
|
||||
if sc.execute("SELECT 1 FROM s_norms WHERE bill_id=? AND x_adopt=1 LIMIT 1", (bid,)).fetchone():
|
||||
sc.execute("UPDATE s_norms SET x_tdel=0 WHERE bill_id=? AND x_adopt=1", (bid,))
|
||||
else:
|
||||
sc.execute("UPDATE s_norms SET x_tdel=0 WHERE bill_id=?", (bid,))
|
||||
return {"ok": True, "sid": sid}
|
||||
if op == "edit":
|
||||
fields = body.get("fields") if isinstance(body.get("fields"), dict) else {}
|
||||
@@ -3209,6 +3218,12 @@ def api_norm_op(sc, body):
|
||||
|
||||
n_uw = _drop_added("s_lme_uw", "session_id=? AND uw_id IS ?", (sid, uw_id), keep_uw)
|
||||
n_proj = _drop_added("s_lme_proj", "session_id=?", (sid,), keep_proj)
|
||||
# 决策 209(2026-10-26 主人定):撤下本条后清单内已无采纳定额 → 原定额恢复(x_tdel=0)。
|
||||
# 原定额的临删**只有取消采纳才恢复**(清单级 unadopt 同款;定额级=撤最后一条采纳时同口径)。
|
||||
if not sc.execute("SELECT 1 FROM s_norms WHERE bill_id=? AND x_adopt=1 LIMIT 1",
|
||||
(n["bill_id"],)).fetchone():
|
||||
sc.execute("UPDATE s_norms SET x_tdel=0 WHERE bill_id=? AND COALESCE(x_adopt,0)=0",
|
||||
(n["bill_id"],))
|
||||
return {"ok": True, "sid": sid, "dropped_lme_uw": n_uw, "dropped_lme_proj": n_proj}
|
||||
return {"ok": False, "msg": "未知操作:%s" % op}
|
||||
|
||||
@@ -5000,7 +5015,8 @@ def api_schema():
|
||||
"清单写": [
|
||||
r("POST", "/api/session/bill/op", "清单操作",
|
||||
{"op*": "insert_above|insert_below|del|tdel|untdel|edit", "bill_id*": "",
|
||||
"fields": "edit 时 {Name,Attr,Unit,Quantity,Remark}"},
|
||||
"fields": "edit 时 {Name,Attr,Unit,Quantity,Remark}",
|
||||
"_tdel": "tdel=清单下全部定额一并临删;untdel=恢复(采纳清单只恢复采纳定额,决策 209)"},
|
||||
{"id": "insert 返回新行id(供 edit/adopt 接力)"}),
|
||||
],
|
||||
"定额写": [
|
||||
@@ -5215,26 +5231,38 @@ def api_search(body):
|
||||
# 工具栏独立检索(/api/hist/search)不受限。被点清单自己的记录亦不在本组集合内。
|
||||
res = [r for r in res if r.get("bill_id") in allowed]
|
||||
if typ == "bill" and res:
|
||||
# 决策 152:清单绑定的询价附件 → 工作台历史对比框可下载(file/file_sha/file_url 同工料机行)
|
||||
c2 = conn()
|
||||
try:
|
||||
m = {}
|
||||
for bid_, fid_, nm_, sha_ in c2.execute(
|
||||
"""SELECT a.bill_id, f.id, f.original_name, f.sha256 FROM bill_attach a
|
||||
JOIN inquiry_files f ON f.id=a.file_id WHERE a.bill_id IN (%s)"""
|
||||
% ",".join("?" * len(res)), [r.get("bill_id") for r in res]):
|
||||
m[bid_] = (fid_, nm_, sha_)
|
||||
finally:
|
||||
c2.close()
|
||||
for r in res:
|
||||
hit = m.get(r.get("bill_id"))
|
||||
if hit:
|
||||
r["file"], r["file_sha"] = hit[1] or "", hit[2] or ""
|
||||
r["file_url"] = "/api/admin/inq/file/%d" % hit[0]
|
||||
# 决策 152:清单绑定的询价附件 → 工作台历史对比框可下载;决策 212 起走共享 _fill_bill_attach
|
||||
_fill_bill_attach(res)
|
||||
return {"ok": True, "base_period": match.ym(pf) + ("~" + match.ym(pt) if pt != pf else ""),
|
||||
"rows": res, "total": len(res)}
|
||||
|
||||
|
||||
def _fill_bill_attach(res):
|
||||
"""清单行的询价附件回填(file/file_sha/file_url,同工料机行口径,下载走 /api/admin/inq/file)。
|
||||
决策 152(比对模式)+ 决策 212(2026-10-26 主人定「能合并的尽量合并」):抽成一处共享,
|
||||
比对模式(api_search)与关键字检索(api_hist_search target=bill)两处调用。无 bill_id 的行安全跳过。"""
|
||||
if not res:
|
||||
return
|
||||
ids = [r.get("bill_id") for r in res if r.get("bill_id")]
|
||||
if not ids:
|
||||
return
|
||||
c2 = conn()
|
||||
try:
|
||||
m = {}
|
||||
for bid_, fid_, nm_, sha_ in c2.execute(
|
||||
"""SELECT a.bill_id, f.id, f.original_name, f.sha256 FROM bill_attach a
|
||||
JOIN inquiry_files f ON f.id=a.file_id WHERE a.bill_id IN (%s)"""
|
||||
% ",".join("?" * len(ids)), ids):
|
||||
m[bid_] = (fid_, nm_, sha_)
|
||||
finally:
|
||||
c2.close()
|
||||
for r in res:
|
||||
hit = m.get(r.get("bill_id"))
|
||||
if hit:
|
||||
r["file"], r["file_sha"] = hit[1] or "", hit[2] or ""
|
||||
r["file_url"] = "/api/admin/inq/file/%d" % hit[0]
|
||||
|
||||
|
||||
def _num_or_none(v):
|
||||
"""前端来的数字容错:数字原样;数字字符串转数字;空串/None/垃圾 → None(=不筛)"""
|
||||
if isinstance(v, bool) or v is None or v == "":
|
||||
@@ -5308,6 +5336,8 @@ def api_self_search(body):
|
||||
else:
|
||||
cands = sc.execute("SELECT * FROM s_bills WHERE session_id=? AND id<>? ORDER BY id",
|
||||
(sid, rid)).fetchall()
|
||||
# 决策 211(2026-10-26 主人定):本项目范围同款硬过滤——单位「项」与单价 0 的清单不出
|
||||
cands = [b for b in cands if (b["Unit"] or "") != "项" and (b["Price"] is None or b["Price"] != 0)]
|
||||
qn = match.norm_match(row["Name"]) if row is not None else None
|
||||
qattr = match.norm_match(row["Attr"] or "") if row is not None else None
|
||||
setkey = match.bill_setkey(row["Name"], row["Unit"]) if row is not None else None
|
||||
@@ -5359,6 +5389,9 @@ def api_self_search(body):
|
||||
qn = match.norm_match(row["name"]) if row is not None else None
|
||||
pre = match.norm(row["name"])[:6] if row is not None else None
|
||||
for l in sc.execute("SELECT * FROM s_lmes WHERE session_id=? ORDER BY id", (sid,)).fetchall():
|
||||
# 决策 211(2026-10-26 主人定):本项目范围工料机 0 价不出(NULL 保留)
|
||||
if l["NoTaxPrice"] is not None and float(l["NoTaxPrice"] or 0) == 0:
|
||||
continue
|
||||
if row is None:
|
||||
rows.append({
|
||||
"tier": "检索", "name": l["Name"], "attr": "", "spec": l["Specification"],
|
||||
@@ -5457,6 +5490,9 @@ def api_hist_search(body):
|
||||
for r in res: # 单价类型码 → 名称(0/空=未标注 → 前端显示 —)
|
||||
fk = r.get("fkind")
|
||||
r["fkind_name"] = FILEKIND.get(fk) if fk not in (None, "", 0) else None
|
||||
if body.get("target") != "lme":
|
||||
# 决策 212(2026-10-26 主人定):检索模式清单行同带询价附件(共享 _fill_bill_attach,与比对模式同源)
|
||||
_fill_bill_attach(res)
|
||||
return {"ok": True, "rows": res, "total": len(res)}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user