Files
Aislo/M01_MasterData/M01_MasterData_Store_Revise.py
T
eomsangdonandClaude Opus 5.5 7e6190f8d3 refactor(855-E L3ⓐ): M01 기초 저장 · 검사 · 막힘 세기 = 수식 문서 기준 · 로직 줄 쓰기 = Store_Logic.mirror 한 자리
앞 세션 auto 커밋 cce57c298(Store_Logic 새 길 · /logic 답 머리만 · 판 = 문서 파일 지문 · 개정 = 문서 머리 대조 · 별칭 · 기계 등록 · [신규] · [삭제])에 이어
- Store_Cache: 막힘 세기(blocks · counted)를 문서 파일마다 · 저장 검사 logic_errors = 키 겹침 · 대장(요소 + 문서 키) · 연결 · 문서 막힘(check_logics 로직 줄 검사 걷음) · _docs_of = 문서 전부 · narrow 로직 갈래 걷음 · check_saved(부름 0) 지움
- Store_Save: 기초(로직 파일) 받지 않음(400) · gone · labor_errors(whole) 갈래 걷음
- Store_Logic: 정본 파일에도 새 기초(그 파일 표 키 — 옛 /save 와 같음) · 지움 검사에 조합 · 지운 기초를 부르던 문서 더함(옛 422 그대로) · 쓰는 곳 409 는 Doc.remove 로(옛 자리)
- 시험(옛 /save 로 로직 줄 셈 칸 고침 · /logic 답 셈 칸을 붙든 것 = 죽은 길): 새 test_855_l3_doc_only(로직 파일 없음 + 같이 쓰기 끔 = 켬과 답 같음 · 목록 · 상세 · 저장 · 개정 409 · 판 409 · 별칭 · 신규 · 복사 · 삭제 · 기계 등록)
  · test_m01_cache 셈 칸 /save 검사 셋 · test_794_1 식 고침 /save 422 걷음(셈 칸 고침 = 문서 저장 몫 · /save 는 머리만 씀)
  · test_m01_make 「시험 계산에 돈다」 → 빈 문서로 열림 · test_m01_api · test_m01_text 옛 셈 길 시험은 로직 줄 사본에서 읽음
  · test_854_2_m01_key_book 대장 끊김 = 인력 줄 + 기초 문서 쓰기 · test_794_1b · test_804_7 판 = 문서 파일 · test_802_3 문서 없는 키 = 404(빈 문서 안 지음)
  · test_826_2 좁힌 검사 = 판정만 견줌(기초 흠 글이 문서 꼴) · 로직 갈래 셋 뺌 · test_m01_copy 옛 시트 길 걷고 master_copy 왕복만 · test_854_2_m01_copy_doc 식 복사 → 기본정보 고친 복사
  · test_713_1 · test_796_1 row_print 줄 뺌(row_print 지움)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 08:37:53 +09:00

78 lines
3.0 KiB
Python

"""M01 단가산출 기초 정본 개정 확인 (PLAN 713-1 · 요구서 내역12 4장 10 · 17 · 855 L3 ⓐ 문서 기준).
- 정본 기초(로직 파일 이름 `로직_*.json` · 자체 `로직_자체.json` 뺌)의 문서 머리를 실제로 바꾸는 저장
(지우기 포함)은 「원문 개정 반영」 확인 값(`개정확인`)이 있어야 함 — 없으면 409 + 까닭.
- 대조 = 문서 머리(키 · 이름표 · 이름 · 결과단위 · 출처 · 부품) — 같은 머리를 그대로 다시 보냄은 대상 밖.
- 자체 기초 · 요소 파일(인력 · 재료 · 표 …)은 대상 밖 · 판 칸 · 옛 줄 사본은 안 둠 — 정본 이력은 git.
"""
from __future__ import annotations
from decimal import Decimal
from M01_MasterData import M01_MasterData_Doc as doc_store
OWN = "로직_자체.json"
#: 기초 머리 — 화면 [저장]이 보내 문서에 쓰는 칸(셈 칸은 줄 쌓기 문서 저장 몫)
FIELDS = ("키", *doc_store.md.TAGS, *doc_store.HEAD)
WHY = "로직 정본(품셈 원문) 줄을 바꿈 — 「원문 개정 반영」 확인 뒤 저장(개정확인)"
def is_canon(file: str) -> bool:
return file.startswith("로직_") and file.endswith(".json") and file != OWN
def _norm(v):
"""수는 int · float · Decimal 어느 꼴로 와도 같은 글(「10」 · 「10.0」 → 「10」)."""
if isinstance(v, bool) or v is None or isinstance(v, str):
return v
if isinstance(v, (int, float, Decimal)):
return format(Decimal(str(v)).normalize(), "f")
if isinstance(v, list):
return [_norm(x) for x in v]
if isinstance(v, dict):
return {k: _norm(x) for k, x in v.items()}
return str(v)
def _head(row: dict) -> dict:
return _norm({k: row[k] for k in FIELDS if k in row})
def changed(batch: list[dict]) -> list[dict]:
"""정본 기초 머리를 바꾸는 고침 — `[{file, key, op, 이름}]` · 같은 머리를 그대로 다시 보낸 edit 은 뺌."""
have = doc_store.docs()
out = []
for part in batch:
file = str(part.get("file") or "")
if not is_canon(file):
continue
for ch in part.get("changes") or []:
op, key, row = ch.get("op"), str(ch.get("key") or ""), ch.get("row")
old = have.get(key)
if (
op == "edit"
and old is not None
and isinstance(row, dict)
and _head(row) == _head(old)
):
continue
name = row.get("이름") if isinstance(row, dict) else None
out.append(
{
"file": file,
"key": key or None,
"op": op,
"이름": name or (old or {}).get("이름"),
}
)
return out
def guard(batch: list[dict], confirmed: bool) -> None:
if confirmed:
return
hits = changed(batch)
if hits:
raise doc_store.store.StoreError(409, {"개정": hits, "까닭": WHY})