Files
Aislo/M02_MasterTemplete/M02_Hopyo_View.py
T
eomsangdonandClaude Opus 5.5 4ccf3527c8 feat(860-3): 호표 목록에 엑셀 금액 · 우리 금액 — 우리 = [수정] 창 「우리 단가」 판 셈 그대로
- 서버 hopyo-sums/{키} = 호표마다 {번, 엑셀, 우리} · 우리 = Hopyo_View.of 문서 판 「우리」 → Labor_Router._calc 줄 반영 합(창과 같은 길 · 새 셈 없음) · 못 셈 = 빈 값
- 목록 먼저 그리고 금액은 뒤에서 채움(북부청 68 호표 = 목록 뒤 약 17 초) · 읽는 중 「…」
- 줄 = 「엑셀 · 우리」 수만(꼬리표는 목록 머리 「금액 = 엑셀 · 우리」 · 풍선말) · 두 값 다르면 경고 색 · 좁은 폭(1277)에서 이름이 먼저 「…」 · n/m 안 잘림
- 시험: test_860_3_made_sk 목록 엑셀 = 엑셀 호표 금액 · 우리 = 창 길(hopyo-view → labor calc) 같음(우리 금액을 고정 수로 안 묶음)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 13:45:29 +09:00

134 lines
7.2 KiB
Python

"""M02 엑셀 불러오기 [수정] 보기(PLAN 809-1 · 요구 702 · 703) — 호표 하나 → 일위대가 문서 미리보기 + 줄 표지 · 읽기만.
경쟁사 로직 인정 · 요소만 연결 — 문서 줄 = 엑셀 줄 하나씩 고정 줄(엑셀 숫자 그대로 · `Fixed.line_of` ·
[내 일위대가로] 와 같은 이음 규칙 · 금액 = 엑셀). 줄 표지:
· 로직 줄 = 단산 N 참조 → 「단가산출」(번 · 가져온 식 SK 로 엶) · 일위 N 참조 → 「일위대가」(번 · 하위 호표 보기)
· 요소 줄 = 그 밖(인력 · 재료 · 기계 · 유가 · 율 · 고정 수) — 이음 있음 = 「연결됨」(이음) ·
후보 있음 = 「후보」(키 · 이름) · 없음 = 「못 이음」(엑셀 값 그대로) · 자재 줄 = `판정`(단가산출 길과 같은 말 · 859-4)
· 엑셀 = 줄 금액(노무비 · 재료비 · 경비 · 계)
문서 = 불러온 일위대가 판 「엑셀」(`본뜬.단가기준` · 859-4 — 화면이 「우리」 로 바꿔 미리 셈) · 이음 = 같은 올림 단서로.
기초 판정 · 2차 풀이 없음 · 저장 없음.
"""
from __future__ import annotations
from pathlib import Path
from typing import Any
from M02_MasterTemplete import M02_Hopyo_Build as hbuild
from M02_MasterTemplete import M02_Hopyo_Fixed as hfix
from M02_MasterTemplete import M02_Hopyo_Store as hopyo_store
from M02_MasterTemplete import M02_Labor_Fixed as fixed
from M02_MasterTemplete import M02_Labor_Ref as refs
from M02_MasterTemplete import M02_MasterTemplete_Store as store
LOGIC, ELEMENT = "로직", "요소"
SK, SC = "단가산출", "일위대가"
LINKED, NEAR, NONE = "연결됨", "후보", "못 이음"
MONEY = ("노무비", "재료비", "경비", "계")
def _name(linker: hfix.Linker, code: str) -> str:
row = (linker.whole.numbers.get(code[:2]) or {}).get(code) or {}
return str(row.get("이름") or "")
def mark(line: dict[str, Any], one: dict[str, Any], linker: hfix.Linker) -> dict[str, Any]:
"""엑셀 줄 하나 표지 — 로직(단가산출 · 일위대가) / 요소(연결됨 · 후보 · 못 이음)."""
ref = line.get("참조") or {}
money = line.get("금액") or {}
out: dict[str, Any] = {
"차례": int(line.get("차례", 0)),
"엑셀": {k: money.get(k) for k in MONEY},
}
if ref.get("종류") == "단산" and ref.get("번"):
return {**out, "갈래": LOGIC, "표지": SK, "번": int(ref["번"])}
if ref.get("종류") == "일위" or hfix.kind_of(line) == "호표":
return {**out, "갈래": LOGIC, "표지": SC, "번": int(ref.get("번") or 0) or None}
fx = one.get("고정") or {}
if hfix.linked(one):
link = {k: v for k, v in (fx.get("이음") or {}).items() if v}
rate = fx.get("비율")
return {**out, "갈래": ELEMENT, "표지": LINKED, "이음": link or {"비율": rate["기준"]}}
if v := linker.verdict(line): # 자재 줄(불러오기 길) = 단가산출 길 판정 · 후보(이름 규격)
cands = linker.find(line, hfix.excel_mat(line))["후보"]
near = [{"키": c["키"], "이름": f"{c.get('이름') or ''} {c.get('규격') or ''}".strip()} for c in cands if c.get("키")] # fmt: skip
out["판정"] = v
else:
near = [{"키": c, "이름": _name(linker, c)} for c in linker.candidates(line)]
if near:
return {**out, "갈래": ELEMENT, "표지": NEAR, "후보": near}
return {**out, "갈래": ELEMENT, "표지": NONE}
def view(source: str | Path, key: str, no: int) -> dict[str, Any]:
"""파일 층 HP 의 호표 하나 보기(`of`)."""
linker = hfix.Linker(True, hfix.clues(source, key))
return of(hopyo_store.read(Path(source), key), no, linker)
def sums(source: str | Path, key: str) -> list[dict[str, Any]]:
"""호표 목록 두 금액(860-3) `[{번, 엑셀, 우리}]` — 엑셀 = 엑셀 호표 금액 · 우리 = [수정] 창 「우리 단가」 판과
같은 서버 셈(`of` 문서 · `본뜬.단가기준` 우리 → `M02_Labor_Router._calc` 의 줄 반영 합 · 못 셈 = None)."""
from M02_MasterTemplete import M02_Labor_Router as labor_router
book = hopyo_store.read(Path(source), key)
linker, out = hfix.Linker(True, hfix.clues(source, key)), []
for h in book.get("호표") or []:
no = int(h["번"])
doc = of(book, no, linker)["문서"]
doc["본뜬"] = {**doc["본뜬"], fixed.BASIS: fixed.OURS}
try:
got = labor_router._calc(f"제{no}호표", labor_router.CalcBody(doc=doc))
ours = (got.get("반영합") or {}).get("계")
except Exception: # noqa: BLE001 — 한 호표 못 셈 = 그 칸 빈 값(목록은 그림)
ours = None
out.append({"번": no, "엑셀": (h.get("금액") or {}).get("계"), "우리": ours})
return out
def of(book: dict[str, Any], no: int, linker: hfix.Linker | None = None) -> dict[str, Any]:
"""호표 하나 → `{번, 이름, 규격, 단위, 금액, 문서 {이름, 단위, 담은로직, 자재}, 줄 [표지]}` — 문서 줄 차례 = 엑셀 줄 차례."""
hopyo = next((h for h in book.get("호표") or [] if int(h["번"]) == int(no)), None)
if hopyo is None:
raise store.StoreError(404, f"없는 호표 「제{no}호표」")
rows = hopyo.get("줄") or []
linker, taken = linker or hfix.Linker(True), set()
where = {"파일": book.get("파일") or "", "호표": int(no)}
lines, marks = [], []
for line in rows:
one = hfix.line_of(line, [x for x in rows if x is not line], where, taken, linker)
lines.append(one)
marks.append(mark(line, one, linker))
name = " ".join(x for x in (hopyo.get("이름"), hopyo.get("규격")) if x)
born = {"층": hbuild.ORIGIN, "파일": where["파일"], fixed.BASIS: fixed.EXCEL} # 859-4 기본 판
doc = {
"이름": name,
"단위": hopyo.get("단위") or None,
"담은로직": lines,
"자재": [],
"본뜬": born,
}
head = {k: hopyo.get(k) for k in ("번", "이름", "규격", "단위", "금액")}
return {**head, "문서": doc, "줄": marks}
def listing(folder: str | Path, key: str, to: str | Path) -> dict[str, Any]:
"""엑셀 보기 머리 · 목록 — 파일 줄 + 검산 · 호표마다 `맞춤` [연결됨 + 로직 줄, 줄 수] ·
`줄상태 [[차례, 표지, 이어짐]]` · `만든` SC(만들 층 `to` · 이 파일 층 것만)."""
book = hopyo_store.read(Path(folder), key)
made = hbuild.confirmed(to, refs.where(Path(folder)))
linker, units = hfix.Linker(True, hfix.clues(folder, key)), []
for h in book.get("호표") or []:
no = int(h["번"])
marks = of(book, no, linker)["줄"]
state = [
[i, m["표지"], m["갈래"] == LOGIC or m["표지"] == LINKED] for i, m in enumerate(marks)
]
head = {k: h.get(k) for k in ("번", "이름", "규격", "단위", "금액", "행") if k in h}
units.append({**head, "맞춤": [sum(x[2] for x in state), len(state)], "줄상태": state,
"만든": made.get(hbuild.mark(key, no))}) # fmt: skip
ready = [sum(h["맞춤"][0] for h in units), sum(h["맞춤"][1] for h in units)]
head = {**hopyo_store.brief(book), "검산": book.get("검산"), "셈": {"끝": True}}
return {**head, "호표": units, "맞춤": ready}