Merge remote-tracking branch 'origin/sub_laptop_7' into sub_laptop_3

This commit is contained in:
2026-10-05 20:49:53 +09:00
3 changed files with 61 additions and 3 deletions
+33 -3
View File
@@ -153,15 +153,43 @@ def clean_doc(kind: str, doc: Any) -> dict[str, Any]:
단위=unit or pill.get("단위") or None,
배=pill.get("배") or 1, # ponytail: 저장 때 적음 · 마스터 결과단위가 바뀌면 다시 저장
담은로직=[{"로직": line["로직"], "입력값": line["입력값"]}],
**origin(line["로직"]),
)
else:
if not name:
raise _bad("사전조합 이름이 빔")
out.update(이름=name, 단위=unit or None, 담은로직=_combo_lines(doc, key))
out.update({k: str(doc.get(k) or "").strip() for k in ("구분", "상세구분")})
out["본뜬"] = doc["본뜬"] if isinstance(doc.get("본뜬"), dict) else None
return out
def origin(code: str) -> dict[str, Any]:
"""단가승격 칸 — 원 로직의 구분 · 상세구분 + 연결 {로직 키, 출처 글}(51-12 · 없으면 빈 글)."""
from M01_MasterData import M01_MasterData_Store as m01
try:
got = m01.loaded()[1].logic(code)
except m01.cm.mf.FormulaError:
got = {}
return {
"구분": got.get("구분") or "",
"상세구분": got.get("상세구분") or "",
"연결": {"로직": code, "출처": got.get("출처") or ""},
}
def filled(kind: str, doc: Any) -> Any:
"""옛 서고 문서(51-12 앞) 읽을 때 칸 채움 — 승격 = 원 로직 것 · 사전조합 = 빈 글(화면 몫)."""
if not isinstance(doc, dict) or kind not in PREFIX or "구분" in doc:
return doc
if kind == "precombo":
return {**doc, "구분": "", "상세구분": ""}
line = (doc.get("담은로직") or [{}])[0]
code = str(line.get("로직") or "") if isinstance(line, dict) else ""
return {**doc, **origin(code)}
def _combo_lines(doc: dict, key: str) -> list[dict[str, Any]]:
"""참조 줄 `{참조, 수량, 메모}` · 로직 줄 `{로직, 입력값, 메모, 수량}`(51-11) — 검사는
일위대가와 같은 길(`labor.clean` · 같은 로직 · 같은 참조 두 번 · 입력값) · 수량 기본 {손: 1}."""
@@ -217,12 +245,14 @@ def create(kind: str, doc: dict[str, Any]) -> dict[str, Any]:
def summary(folder: Path, kind: str, key: str, expand: Expand | None = None) -> dict[str, Any]:
"""층 목록 한 줄에 붙일 것 — `{제목, 단위}` · `expand` 면 1 단위 기준 계(`기준금액` · 51-4)."""
"""층 목록 한 줄에 붙일 것 — `{제목, 단위, 구분, 상세구분, 연결}`(51-12) · `expand` 면
1 단위 기준 계(`기준금액` · 51-4)."""
try:
doc = json.loads((Path(folder) / kind / f"{key}.json").read_bytes())
doc = filled(kind, json.loads((Path(folder) / kind / f"{key}.json").read_bytes()))
except (OSError, ValueError):
return {}
out = {"제목": doc.get("이름"), "단위": doc.get("단위")}
keep = ("구분", "상세구분", "연결")
out = {"제목": doc.get("이름"), "단위": doc.get("단위"), **{k: doc.get(k) for k in keep}}
if expand is not None:
layer, owner = where(folder)
base = expand({"층": layer, "주인": owner, "키": key}).get("기준") or {}
@@ -309,6 +309,7 @@ async def read_layer_template(
raise HTTPException(status_code=404, detail="양식을 찾을 수 없습니다.")
found["층"] = layer
found["출처"] = layers.read_manifest(folder).get(f"{kind}/{name}")
found["문서"] = refs.filled(kind, found["문서"]) # 옛 서고 문서 구분 · 상세구분(51-12)
return found
+27
View File
@@ -407,3 +407,30 @@ def test_사전조합이_자기_자신을_담으면_422_수량_기본_1(world):
},
)
assert e.value.status == 422 and "자기 자신" in e.value.detail
def test_서고_구분_상세구분_연결_승격은_원_로직_사전조합은_고른_값_옛_문서는_읽을_때(world):
import M01_MasterData.M01_MasterData_Store as m01
row = m01.loaded()[1].logic(TEN)
sp = _promote(world["system"], 구분="틀림", 상세구분="틀림", 연결={"로직": "x"})
doc = _read(world["system"], "promote", sp)
assert row["구분"] and row["상세구분"]
assert (doc["구분"], doc["상세구분"]) == (row["구분"], row["상세구분"]) # 화면 값 안 받음
assert doc["연결"] == {"로직": TEN, "출처": row.get("출처") or ""}
sc = _combo(world["system"], [{"참조": {**SYS, "키": sp}}])
assert (_read(world["system"], "precombo", sc)["구분"], "") == ("", "")
with store.at(world["system"]):
have = store.read("precombo", sc)
store.write("precombo", sc, have["판"], {**have["문서"], "구분": " 가 ", "상세구분": "나"})
got = _read(world["system"], "precombo", sc)
assert (got["구분"], got["상세구분"]) == ("가", "나")
# 옛 문서(칸 없음) — 승격은 원 로직 것 · 사전조합은 빈 글
old = {k: v for k, v in doc.items() if k not in ("구분", "상세구분", "연결")}
(world["system"] / "promote" / f"{sp}.json").write_text(json.dumps(old), encoding="utf-8")
assert refs.filled("promote", old)["연결"] == doc["연결"]
assert refs.filled("precombo", {"담은로직": []})["구분"] == ""
rows = [{"종류": "promote", "이름": sp}, {"종류": "precombo", "이름": sc}]
refs.summaries(world["system"], rows)
assert (rows[0]["구분"], rows[0]["상세구분"]) == (row["구분"], row["상세구분"])
assert (rows[1]["구분"], rows[1]["상세구분"], rows[1]["연결"]) == ("가", "나", None)