Merge branch 'sub_laptop_1' of C:/Aislo_wt/sub_laptop_1 into main_laptop_1

This commit is contained in:
2026-11-17 21:11:38 +09:00
+86 -28
View File
@@ -343,7 +343,54 @@ def _json(value: Any) -> Any:
return labor._json(value)
class _One:
"""M01 색인 위에 가져온 줄 하나 — `logic(키)` 만 가로챔(문서 변환 색인 · 그 밖 그대로)."""
def __init__(self, whole: Any, key: str, row: dict) -> None:
self._whole, self._key, self._row = whole, key, row
def logic(self, ref: str) -> dict:
return self._row if ref == self._key else self._whole.logic(ref)
def __getattr__(self, name: str) -> Any:
return getattr(self._whole, name)
def _doc_of(bare: dict, whole: Any) -> tuple[dict, list[str], dict]:
"""검산 문서(855 2-C3) — 가져온 줄(엑셀 단가 · 고침 없음)을 줄 차례 그대로 문서로(다듬기 없음 ·
금액 줄 k = 줄 정체 k) · 안쪽 산근 줄 = 형제 SK 연결(문서 셈 · 부르는 쪽 단가기준) →
(문서, 줄 정체, {중간 이름: 기호})."""
from M02_MasterTemplete import M02_Doc_Copy as dc
key = str(bare.get("키") or "SK-000000")
row = {**row_of(bare), "키": key}
row["호표"] = [dict(x) for x in row["호표"]]
for item in row["호표"]: # 형제 SK 줄 = 아래에서 연결로 갈음 — 변환 자리값
if item.get("참조") and item.get("값묶음") is None:
item["값묶음"] = dict.fromkeys(COSTS, Decimal(0))
master = _One(whole, key, row)
doc, _ = dc.cv.convert(master, row, dc.given_of(master, key, bare.get("입력값")))
by = {dc.md.var_id(v): v for v in doc.get("변수") or []}
for item, line in zip(row["호표"], doc.get("금액") or []):
var = by.get(str(line.get("단가") or "").removesuffix(".계"))
if not item.get("참조") or var is None:
continue
ref = item["참조"]
link = {
"갈래": "단가산출",
"키": ref["키"],
"참조": {"층": ref["층"], "주인": ref.get("주인")},
}
if item.get("참조비목") in COSTS: # 안쪽 산근의 그 비목만(`Doc_Import._attach` 와 같음)
link["칸"] = item["참조비목"]
line["단가"], line["비목"] = dc.md.var_id(var), item["참조비목"]
var["연결"] = link
mids = {str(v.get("열쇠")): dc.md.var_id(v) for v in doc.get("변수") or []}
return doc, sd.line_ids(row), mids
def _run(doc: dict, whole: Any) -> dict:
"""SK 셈(`to_price` 전 · 후 1 단위) — `Sangeun_Calc.run` 한 길(2-C1 몫 · 검산은 `_doc_of`)."""
from M02_MasterTemplete import M02_Sangeun_Calc as calc
return calc.run(sd.clean(doc, None, whole), whole)
@@ -366,8 +413,13 @@ def _same(mine: Any, excel: Any) -> bool:
def check(doc: dict, whole: Any = None) -> dict[str, Any]:
"""검산 — 가져온 줄(엑셀 단가 · 고침 없음)을 엔진으로 다시 셈 → 엑셀 금액 · 줄마다 맞댐 ·
못 셈 = {같음 False, 까닭}."""
"""검산 — 가져온 줄(엑셀 단가 · 고침 없음)을 문서 계산기로 다시 셈(855 2-C3 · 옛 엔진 안 돎) →
엑셀 금액 · 글줄마다 맞댐(글줄 `자리` = 줄 정체 cid ↔ 검산 문서 금액 줄 같은 차례 · `mid:이름` =
중간 변수 값 · `단계:이름` = 단계 계) · 못 셈 = {같음 False, 까닭}."""
from M02_MasterTemplete import M02_Doc_Copy as dc
from M02_MasterTemplete import M02_Doc_Import as dim
from M02_MasterTemplete import M02_Sangeun_Calc as calc
whole = whole or _whole()
meta = doc[KEY]
bare = {k: doc.get(k) for k in ("키", "이름", "단위", "입력값", "환산")}
@@ -375,17 +427,45 @@ def check(doc: dict, whole: Any = None) -> dict[str, Any]:
src = meta.get("원본") or {}
excel = src.get("엑셀금액") or {}
try:
got = _run(bare, whole)
bare = sd.clean(bare, None, whole)
times = calc.ratio_of(bare, row_of(bare), whole) # 1 단위 = 문서 셈 ÷ 배(옛 `1단위`)
except sd.DocError as e:
return {"같음": False, "까닭": str(e), "셈": None, "엑셀": excel, "줄": []}
mine = _money(got)
now = {x.get("cid"): x.get("금액") for x in got.get("줄") or []} | _inner(bare, whole)
try:
mine_doc, ids, mids = _doc_of(bare, whole)
got = dim.run(mine_doc, bare, whole)
except Exception as e: # noqa: BLE001 — 변환 · 셈 틀림 = 맞댈 값 없음
got, ids, mids, mine_doc = {"셈됨": False, "까닭": str(e)}, [], {}, None
money = dc.money(got) if got.get("셈됨") else None
if (
money is None
and mine_doc is not None
and not (mine_doc.get("금액") or mine_doc.get("결과"))
):
money = dict.fromkeys(dc.COSTS, Decimal(0)) # 빈 산근 = 엑셀 0 원(줄 없음 합)
mine = {k: Decimal(str(v)) / times for k, v in money.items()} if money else None
now = {cid: x.get("금액") for cid, x in zip(ids, got.get("줄") or [])}
values = got.get("값") or {}
now |= {f"mid:{k}": values[v] for k, v in mids.items() if isinstance(values.get(v), Decimal)}
steps = got.get("단계") or {}
steps = (
steps
if isinstance(steps, dict)
else {x.get("이름"): x for x in steps if isinstance(x, dict)}
)
now |= {f"단계:{k}": (v or {}).get("계") for k, v in steps.items()}
group = _groups(src.get("글줄"))
lines = [x for x in (_compare(one, now, group=group) for one in src.get("글줄") or []) if x]
ok = bool(mine) and excel != {} and _all_same(mine, excel)
rate = (src.get("계약") or {}).get("낙찰률")
ok = ok or bool(mine and rate and excel and _all_same(_contract(mine, rate), excel))
why = None if ok else (got.get("까닭") or ("엑셀 금액 없음" if not excel else "금액 다름"))
why = (
None
if ok
else (
(dc.why(got) if not money else "") or ("엑셀 금액 없음" if not excel else "금액 다름")
)
)
ok = ok and all(x["같음"] for x in lines)
return _json({"같음": ok, "까닭": why, "셈": mine, "엑셀": excel, "줄": lines})
@@ -403,28 +483,6 @@ def _contract(mine: dict, rate: float) -> dict:
return out | {"계": sum(out.values())}
def _inner(doc: dict, whole: Any) -> dict:
"""엔진 날 셈의 중간 `mid:이름` · 단계 `단계:이름` 계(검산 맞댈 값) · 못 셈 = 빈."""
from M02_MasterTemplete import M02_Sangeun_Calc as calc
m01, key = calc.labor.m01, str(doc.get("키") or "SK-000000")
row = {**row_of(doc), "키": key}
if any(x.get("참조") for x in row["호표"]): # 안쪽 산근 값 채움(797-1 · 셈 길과 같음)
from M02_MasterTemplete.M02_Labor_Expand import Expand
row["호표"] = [dict(x) for x in row["호표"]]
calc._bundles(row, whole, Expand(whole), ())
over = calc._Over(whole, key, row)
try:
auto = {k: v for k, v in m01.mau.values(over, over.logic(key)).items() if v is not None}
given = {**auto, **m01._dec(doc.get("입력값") or {})}
got = calc.labor.mcut.engine(over, key, m01.cm.mf.run(over, key, given))
except Exception: # noqa: BLE001 — 엔진 FormulaError · 셈 틀림 = 맞댈 값 없음
return {}
out = {f"mid:{k}": v for k, v in (got.get("중간") or {}).items()}
return out | {f"단계:{x.get('이름')}": x.get("계") for x in got.get("단계") or []}
def _groups(texts: Any) -> dict[str, Decimal]:
"""첫 자리가 같은 값 든 글줄 여럿 → 첫 자리별 값 합(814-1 기계 노 · 재 · 경 세 글줄 = 묶은
한 줄 · 노 줄만 딸린 기계까지 자리들)."""