"""145-1 B09 단가산출근거 · 목록표 — 단가산출 줄 → 산근 블록 · 엑셀 검산 · 같은 산근 하나 · 빈 표. - 산근 = 155-4 갈래(사용자 뜻 · 145 정함 뒤집음) — 일위대가 로직 줄 중 단가산출 줄(승격 아님) + 사전조합 안 단가산출 줄 · 일위대가화(승격 · 옛 SP) 줄 자체는 산근 아님(대가 블록) - 줄 단가 = M02 엔진 줄 금액 ÷ 수량(841-1 · 사본 단가 묶음 · B09 단가 책 안 읽음) · 줄 금액 = ROUNDDOWN(단가 × 1 단위 수량, 1) · 총계 = 비목마다 ROUNDDOWN 0 — 엑셀 단가산출근거 제 6호표(뒷채움) 줄 값 · 총계 8,328(6,878 · 538 · 912)과 같음 · 산근 합 = M02 엔진 기준 - 관급 · 별도계상 재료(supply) = 산근 안 0원 · `aside` 에 금액(841-1) - 같은 로직 + 같은 입력값 = 산근 하나(쓰는 구조물이 늘어남) · 입력이 다르면 둘 · 번호 = 첫 등장 - 사본 없으면 빈 표 + 「연결 없음」 · 조합 밖 토공 · 운반 산근 안내 한 줄 · 작업량 Q = ROUND 2 """ import asyncio import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) from B09_Estimation import B09_Estimation_Router as router_mod # noqa: E402 from B09_Estimation import B09_Estimation_Sangeun as sg # noqa: E402 from M02_MasterTemplete import M02_Item_Prices as item_prices # noqa: E402 STONE = "GF000219" # 돌쌓기 메쌓기(인력) — 석공 0.195 · 보통인부 0.156 / ㎡ NET = "GC000337" # 낙석방지망 — 노무 · 크레인(중기) · 자재 셋 NET_IN = {"구분": "기계식", "방지망": "포켓식", "지역": "전국평균", "크레인": "2104-0010"} SP_REF = {"층": "system", "주인": None, "키": "SP-000001"} SC_REF = {"층": "system", "주인": None, "키": "SC-000001"} def _snapshot(folder: Path, rows, values=None, copies=None) -> Path: folder.mkdir(parents=True, exist_ok=True) labor = { "줄": {"종류": "일위대가", "담은로직": rows}, **({"참조사본": copies} if copies else {}), } from M02_MasterTemplete import M02_Doc_Copy as dc from M02_MasterTemplete import M02_Item_Bundle as item_bundle docs = dc.closure( item_prices.master()[1], [STONE, NET] ) # 사본 = 수식 문서 + 자원 줄(855-F B9-6) files = { "수식.json": item_prices.to_json({"그룹": "수식문서", "문서": docs}), "단가.json": item_prices.to_json(item_bundle.collect(docs)), "일위대가.json": labor, "입력값.json": {k: {n: {"값": v} for n, v in d.items()} for k, d in (values or {}).items()}, } for name, data in files.items(): (folder / name).write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8") return folder def _engine(folder: Path, code: str, given=None) -> dict: """M02 셈 기준(사본 수식 문서 셈 · 끝수 뒤 기준 · 855-F B9-6).""" from M02_MasterTemplete import M02_Item_Bundle as item_bundle docs = json.loads((folder / "수식.json").read_text(encoding="utf-8"))["문서"] bundle = json.loads((folder / "단가.json").read_text(encoding="utf-8")) from B09_Estimation import B09_Estimation_Doc_Run as dr from M02_MasterTemplete import M02_Doc_Copy as dc got = dr.solve(item_bundle.load(bundle, docs), docs, code, given or {}) return {"기준": dc.money(got.ans)} def test_단가산출_줄만_산근_블록_단가는_M02_엔진(tmp_path): a = _snapshot(tmp_path / "a", [{"로직": STONE}, {"로직": NET, "승격": True}], {NET: NET_IN}) got = sg.collect([("s1", a)]) (block,) = got["sg"] assert (block["no"], block["logic"], block["unit"]) == (1, STONE, "㎡") lines = block["lines"] assert [(ln["kind"], ln["ref"]["key"], ln["qty"]) for ln in lines] == [ ("labor", "LB000033", 0.195), ("labor", "LB000002", 0.156), ] want = _engine(a, STONE)["기준"] assert block["labor"] == float(want["노무비"]) and block["sum"] == float(want["계"]) assert block["material"] == 0 and block["expense"] == 0 and block["why"] is None assert got["sg_list"][0]["key"] == block["key"] and got["sg_gaps"] == [] assert sg.price_of(got, block["key"]) == { "no": 1, "labor": block["labor"], "material": 0.0, "expense": 0.0, "sum": block["sum"], } # fmt: skip def test_중기_자재_단가_M02_엔진_별도계상은_0원(tmp_path): a = _snapshot(tmp_path / "a", [{"로직": NET}], {NET: NET_IN}) (block,) = sg.collect([("s1", a)])["sg"] kinds = [ln["kind"] for ln in block["lines"]] assert kinds == ["labor", "labor", "machine", "material", "material", "material"] want = _engine(a, NET, NET_IN)["기준"] assert [block[p] for p in (*sg.PARTS, "sum")] == [ float(want[k]) for k in ("노무비", "재료비", "경비", "계") ] (apart,) = sg.collect([("s1", a)], supply=lambda key: "별도")["sg"] mats = [ln for ln in apart["lines"] if ln["kind"] == "material"] assert all(ln["material"] == 0 and ln["aside"] for ln in mats if ln["qty"]) assert apart["material"] < block["material"] and apart["labor"] == block["labor"] def test_엑셀_6호표_뒷채움_검산(): """단가산출근거 C285 = 8,328(6,878 · 538 · 912) — 보통인부 0.018 × 165,545 · 굴삭기(0.2m3) 0.07 × 중기목록표 55,700 · 7,695 · 13,041(줄 2,979.8 · 3,899.0 · 538.6 · 912.8 · 계 8,330.2 → 비목마다 버림).""" zero = dict.fromkeys(sg.PARTS, 0.0) labor = {**zero, "labor": sg._money(165545, 0.018)} machine = {p: sg._money(v, 0.07) for p, v in zip(sg.PARTS, (55700, 7695, 13041))} assert labor["labor"] == 2979.8 assert (machine["labor"], machine["material"], machine["expense"]) == (3899.0, 538.6, 912.8) assert sg.block_totals([labor, machine]) == { "labor": 6878, "material": 538, "expense": 912, "sum": 8328, } # fmt: skip assert sg.block_totals([labor, {**machine, "material": None}])["sum"] is None # 빈칸 = 빈칸 def test_같은_로직_같은_입력은_하나_다르면_둘_사전조합_안_줄도_같은_산근(tmp_path): a = _snapshot(tmp_path / "a", [{"로직": NET}], {NET: NET_IN}) b = _snapshot(tmp_path / "b", [{"로직": NET}], {NET: {**NET_IN, "": ""}}) other = {**NET_IN, "방지망": "비포켓식"} c = _snapshot(tmp_path / "c", [{"로직": NET}], {NET: other}) sc = {"이름": "사전조합", "담은로직": [{"로직": NET, "입력값": NET_IN}]} sp = {"담은로직": [{"로직": NET, "입력값": other}], "배": 1} # 옛 SP = 일위대가화 = 산근 아님 d = _snapshot( tmp_path / "d", [{"로직": "", "참조": SC_REF}, {"로직": "", "참조": SP_REF}, {"로직": STONE}], copies={"참조|system||SC-000001": sc, "참조|system||SP-000001": sp}, ) got = sg.collect([("s1", a), ("s2", b), ("s3", c), ("s4", d)]) blocks = got["sg"] assert [(x["no"], x["logic"], x["uses"]) for x in blocks] == [ ( 1, NET, ["s1", "s2", "s4"], ), # 빈 입력 칸은 무시 · 사전조합 안 줄(같은 로직 · 입력) = 같은 산근 (2, NET, ["s3"]), (3, STONE, ["s4"]), ] assert blocks[0]["key"] == sg.sangeun_key(NET, {**NET_IN, "x": None}, 100, {}) assert blocks[0]["key"] != sg.sangeun_key(NET, NET_IN, 90) # 켜쌓기율이 다르면 다른 산근 def test_사본_없으면_빈_표_연결_없음(tmp_path, monkeypatch): got = sg.collect([("s1", tmp_path / "없음")]) assert got["sg"] == [] and got["sg_list"] == [] and got["sg_gaps"] == [] assert got["sg_notes"] == [sg.NO_SOURCE, sg.EMPTY] plain = _snapshot(tmp_path / "p", [{"로직": STONE, "승격": True}]) # 일위대가화만 = 빈 표 assert sg.collect([("s1", plain)])["sg"] == [] async def fake_materials(_project_id): return {} monkeypatch.setattr(router_mod, "material_sheets", fake_materials) sheets = asyncio.run(router_mod.payload("p", tmp_path))["sheets"] assert sheets["sg"] == [] and sheets["sg_list"] == [] assert sg.EMPTY in sheets["sg_notes"] and sg.NO_SOURCE in sheets["sg_notes"]