Files
Aislo/B09_Estimation/B09_Estimation_Refresh.py
T
eomsangdonandClaude Opus 5.5 40b974c0c0 feat(B09 데이터 점검): [업데이트] 한 곳 — 단가 다시 굳힘 + 원본 바뀐 구조물 사본 재적용 · 미리 보기 창 (PLAN 703-3)
- POST …/estimation/prices = 연결된 구조물 사본 중 원본이 바뀐 것만 재적용(B09_Estimation_Refresh · 막힌 사본 = 알림 · 나머지 함) → 수요 다시 → 단가 책 다시 굳힘 · 덮개 그대로 · 답 notes 첫 줄 「단가 줄 N 바뀜 · 사본 K · 고친 칸 M 그대로」
- POST …/estimation/prices/preview = 바뀌는 단가 줄(새 · 값 바뀜) · 다시 가져올 사본 · 지킬 고친 칸 · 노임 판 전 → 후(쓰지 않음)
- 단가 책에 노임 판(labor_edition · 구분마다 M01 인력 판) · 책 견줌 book_diff(book_stale 도 같이 씀)
- UI_Check = [업데이트] 누름을 먼저 잡아 미리 보기 창 → [적용] 이면 원래 단추 일 · 호버 글
- 시험 test_703_3_b09_refresh(미리 보기 수 = 적용 수 · 판 · 재적용 원본 바뀐 것만 · 덮개 그대로)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 13:46:28 +09:00

73 lines
3.2 KiB
Python

"""B09 [업데이트] 한 곳(PLAN 703-3) — 단가 책 다시 굳힘 + 원본이 바뀐 구조물 사본 [재적용]을 함께.
미리 보기(`preview`) = 바뀌는 단가 줄(새 줄 + 바뀐 줄 · 지금 수요) · 다시 가져올 구조물 사본
(연결된 것 중 원본이 바뀐 것만 · 원본 없음 = 그대로) · 지킬 고친 칸(덮개 칸 수 · 702-4 —
재적용 · 새 판 뒤에도 남음) · 노임 판(굳힌 판 → 지금 M01 판 · 옛 책 = 굳힌 날)
적용(`reapply_changed` → 부르는 쪽이 수요 다시 → `prices.refresh_book`) — 사본 먼저(수요가 바뀜) ·
덮개(사용자 값)는 안 건드림 · 사본 하나가 막혀도 나머지는 함(막힌 것 = 알림).
"""
from __future__ import annotations
from pathlib import Path
from typing import Any
from B09_Estimation import B09_Estimation_Prices as prices
from B09_Estimation.B09_Estimation_Calc_Labor import COPY
from M02_MasterTemplete import M02_Item_Copy as item_copy
from M02_MasterTemplete.M02_Item_Snapshot import linked_snapshots
def changed_copies(root: str | Path) -> list[dict[str, Any]]:
"""연결된 구조물 사본 중 원본(층 · 마스터)이 바뀐 것 `[{폴더, 이름}]`."""
linked = {one["폴더"] for one in linked_snapshots(root).values()}
return [
{"폴더": it["폴더"], "이름": it["이름"] or it["폴더"]}
for it in item_copy.list_items(root)
if it["폴더"] in linked and it["마스터바뀜"]
]
def cover_cells(cover: dict[str, Any] | None) -> int:
"""고친 칸 수 — 덮개 칸(품 · 수량 · 단가) · 복사본 표지 뺌."""
return sum(
len(cell) for lines in (cover or {}).values() for cid, cell in lines.items() if cid != COPY
)
def edition_text(editions: dict[str, str] | None) -> str:
return " · ".join(f"{kind} {day[:7]}" for kind, day in sorted((editions or {}).items()))
def preview(
root: str | Path, book: dict[str, Any] | None, keys: list[str], cover: dict | None
) -> dict[str, Any]:
diff = prices.book_diff(book, prices.refresh_book(keys, book))
before = (book or {}).get("labor_edition")
made = str((book or {}).get("made") or "")[:10]
return {
"단가줄": diff["new"] + diff["changed"],
"새줄": diff["new"],
"바뀐줄": diff["changed"],
"계수": diff["factor"],
"환율": diff["fx"],
"사본": changed_copies(root),
"고친칸": cover_cells(cover),
"노임판": {
"전": edition_text(before) if before else (f"굳힌 날 {made}" if made else "안 굳힘"),
"후": edition_text(prices.labor_editions(keys)),
},
}
def reapply_changed(root: str | Path, who: dict[str, Any] | None = None) -> dict[str, list]:
"""원본이 바뀐 연결 사본 재적용 — `{다시: [이름], 막힘: [이름 — 까닭]}`."""
done, stuck = [], []
for one in changed_copies(root):
try:
item_copy.reapply(root, one["폴더"], who)
done.append(one["이름"])
except (LookupError, ValueError, KeyError, OSError) as error:
stuck.append(f"{one['이름']} — {error}")
return {"다시": done, "막힘": stuck}