Files
Aislo/resources/tester/test_705_1_fixed_line.py
T
eomsangdonandClaude Opus 5.5 a24e0d622c feat(M02·B09 고정 줄): 일위대가 줄 「고정」 갈래 · B09 대가 fixed 줄 · 이음 단가 · 집계표 빠짐 수 (PLAN 705-1)
- M02 일위대가 줄 {고정: 이름 · 규격 · 단위 · 단가 · 이음(노임 · 자재 · 기계) · 출처} — 정리 · 셈(새 파일 M02_Labor_Fixed) · 줄 가름 짝 TS lineId
- 사본 단가 묶음 · B09 단가 책 수요에 이음 키
- B09 대가 줄 fixed — 이은 비목만 단가 책 값 · 못 이음 = 줄 단가 · 덮개 먹음 · 빈칸 안 됨(파이썬 · TS 짝)
- 집계표 — 이은 고정 줄 = 자원 셈 · 이음 없는 줄 = 빠짐 수(summary.fixed · 안내 「고정 줄 n」)
- B09 일위대가표 줄 꼬리표 「고정」 값 넘김
- 시험 test_705_1 12 · test_145_5 응답 칸 목록에 fixed(낡은 단정 고침)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 14:05:47 +09:00

283 lines
14 KiB
Python

"""705-1 고정 줄 갈래 — 품 · 수량 · 단가 숫자를 그대로 적어 둔 일위대가 줄(요구서 1장 · 4장 1 · 2 · 3).
- M02 일위대가 줄 `{고정: {이름 · 규격 · 단위 · 단가 · 이음 · 출처}}` — 정리 · 셈 · 거울(`settle` 파이썬 ↔ TS)
- B09 대가 줄 `fixed` — 이음 있으면 이 공사 단가 책 값 · 없으면 줄 단가 · 덮개 · 거울(Calc_Labor 파이썬 ↔ TS)
- 노임 새 판 = 이은 비목만 따라감 · 품(수량) 그대로 · 원가계산서 빈 줄 0 · 집계표 이음 · 빠짐 수
견본 = `test_145_2_b09_labor_calc`(엑셀 바탕 표 · 사본 꼴) · `test_m02_labor_calc_mirror`(TS 헬퍼).
"""
import copy
import importlib.util
import json
import sys
from pathlib import Path
import pytest
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_Prices as prices # noqa: E402
from B09_Estimation.B09_Estimation_Calc_Labor import compute_labor, daega_price # noqa: E402
from B09_Estimation.B09_Estimation_Labor_Source import daega_inputs # noqa: E402
from B09_Estimation.B09_Estimation_Linked import linked_resource_keys # noqa: E402
from B09_Estimation.B09_Estimation_Summary import compute_summary, hopyo_lines # noqa: E402
from M02_MasterTemplete import M02_Item_Prices as item_prices # noqa: E402
from M02_MasterTemplete import M02_Labor_Doc as labor # noqa: E402
from M02_MasterTemplete import M02_Labor_Fixed as fixed # noqa: E402
from M02_MasterTemplete import M02_MasterTemplete_Store as store # noqa: E402
from M02_MasterTemplete import M02_Item_Snapshot as snapshots # noqa: E402
def _load(name):
spec = importlib.util.spec_from_file_location(name, Path(__file__).with_name(f"{name}.py"))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
b145 = _load("test_145_2_b09_labor_calc")
m02 = _load("test_m02_labor_calc_mirror")
LB = "LB000033" # 메쌓기 인력 줄 직종(견본 사본 · M01 에 있음)
def _fx(name, price, link=None, unit="인"):
return {"이름": name, "규격": "", "단위": unit, "단가": price, "이음": link or {}}
# ── M02 일위대가 줄 ────────────────────────────────────────────────────────
def test_M02_정리_꼴과_막힘():
doc = labor.clean(
{
"담은로직": [
{"로직": m02.TEN, "수량": None},
{
"고정": {
**_fx("보통인부", {"노무비": "1,000"}, {"노임": LB}),
"출처": {"파일": "a.xlsx", "호표": 3, "몰래": 1},
},
"수량": {"손": 0.5},
},
]
}
)
line = doc["담은로직"][1]
assert line["고정"] == {
"이름": "보통인부", "규격": "", "단위": "인",
"단가": {"노무비": 1000, "재료비": 0, "경비": 0},
"이음": {"노임": LB, "자재": None, "기계": None},
"출처": {"파일": "a.xlsx", "호표": 3},
} # fmt: skip
assert line["수량"] == {"손": 0.5} and labor.line_id(line) == "고정|보통인부||인"
bad = [
[{"고정": _fx("", {})}], # 이름 없음
[{"고정": _fx("a", {"노무비": "글"})}], # 단가가 수 아님
[{"고정": _fx("a", {}, {"노임": "MT000008"})}], # 이음 머리 틀림
[{"고정": _fx("a", {}, {"자재": "MT999999"})}], # M01 에 없음
[{"고정": _fx("a", {})}, {"고정": _fx("a", {"재료비": 1})}], # 같은 줄 두 번
]
for lines in bad:
with pytest.raises(store.StoreError) as e:
labor.clean({"담은로직": lines})
assert e.value.status == 400
def _mixed_doc():
"""섞인 호표 — 로직 줄 셋 + 고정 줄(이은 노임 · 이은 자재 · 손 단가) + 자재."""
return labor.clean(
{
"열": "rv",
"담은로직": [
{"로직": m02.TEN, "수량": None},
{"고정": _fx("석공", {"노무비": 1}, {"노임": LB}), "수량": {"손": 0.3}},
{"로직": m02.THOUSAND, "수량": {"손": 4}},
{
"고정": _fx("자갈", {"재료비": 1}, {"자재": m02.MAT}, unit=""),
"수량": {"손": 2},
},
{"고정": _fx("잡재료", {"재료비": 1234.5}, unit="식"), "수량": None},
{"로직": m02.PLAIN, "수량": None},
],
"자재": [{"코드": m02.MAT, "수량": None}],
}
)
@pytest.mark.parametrize(
"values",
[{}, {"사석 수상고르기|㎡": 2.5, f"자재|{m02.MAT}": "3"}, {"나무식재|본": "1,200"}],
)
def test_M02_섞인_호표_파이썬과_TS_가_같은_답(values):
doc = _mixed_doc()
answer = labor.calc(doc, {})
py = labor.settle(answer, doc, values)
m02._same(py, m02._ts(answer, doc, values))
assert py == labor.calc(doc, values)
stone, gravel, misc = (ln for ln in py["줄"] if "고정" in ln)
whole = labor.m01.loaded()[1]
assert stone["기준"]["노무비"] == whole.get(LB)["값"] and stone["이은"] == ["노무비"]
assert stone["반영"]["노무비"] == pytest.approx(stone["기준"]["노무비"] * 0.3)
assert gravel["이은"] == ["재료비"] and gravel["기준"]["재료비"] != 1
assert misc["기준"] == {"노무비": 0, "재료비": 1234.5, "경비": 0, "계": 1234.5}
assert (
misc["이은"] == [] and misc["수량"] is None and misc["반영"] is None
) # 손 단가 · 수량 없음
def test_M02_사본_셈_이음_단가_묶음(tmp_path):
"""사본 `단가.json` 에 이은 키가 실림(price_bundle) · 사본 셈 = 층 셈."""
from M02_MasterTemplete.M02_Item_Source import price_bundle
doc = _mixed_doc()
bundle = price_bundle({"로직": [], "줄": doc}, tmp_path)
got = item_prices.load_prices(bundle)
assert got.get(LB)["값"] == labor.m01.loaded()[1].get(LB)["값"]
snap = item_prices.calc({"줄": doc}, bundle, {}, {})
fixed_lines = [ln for ln in snap["줄"] if "고정" in ln]
assert [ln["이은"] for ln in fixed_lines] == [["노무비"], ["재료비"], []]
# ── B09 대가 셈(바탕 표 = 엑셀 견본) ──────────────────────────────────────────
def _fixed_blocks():
"""조합 블록 — 노무 줄 + 고정 줄 넷(이은 노임 · 이은 관급 자재 · 이은 중기 · 손 단가)."""
own = {"labor": 100.0, "material": 200.0, "expense": 300.0}
lines = [
{"kind": "labor", "key": "L00017", "name": "보통인부", "qty": 0.1},
{"kind": "fixed", "name": "석공", "qty": 0.2, "own": own,
"link": {"labor": "L00005", "material": None, "machine": None}},
{"kind": "fixed", "name": "파형강관", "qty": 1, "own": own,
"link": {"labor": None, "material": "M00222", "machine": None}},
{"kind": "fixed", "name": "굴착기", "qty": 0.5, "own": own,
"link": {"labor": None, "material": None, "machine": "X00044"}},
{"kind": "fixed", "name": "잡재료", "qty": 2, "own": {"material": 1234.5},
"link": {"labor": "L99999", "material": None, "machine": None}}, # 책에 없음 = 손 단가
] # fmt: skip
for n, ln in enumerate(lines):
ln["cid"] = f"{ln['kind']}:{ln.get('key') or ln['name']}#0"
ln["n"] = n
block = {"id": "DGF", "cover": "S:f", "kind": "조합", "name": "섞인", "spec": "", "unit": "m",
"cite": "", "origin": {}, "lines": lines} # fmt: skip
return {"blocks": [block], "owners": {"pipe@100.0": "DGF"}}
def _line(out, name):
return next(ln for ln in out["daega_blocks"][0]["lines"] if ln["name"] == name)
def test_B09_고정_줄_단가_이음과_손_단가():
out = compute_labor(_fixed_blocks(), b145.SHEETS, {})
assert _line(out, "석공")["prices"] == {"labor": 258935, "material": 200, "expense": 300}
assert _line(out, "파형강관")["prices"]["material"] == 0 # 관급 = 대가 안 0원
assert _line(out, "굴착기")["prices"] == {"labor": 47231, "material": 7784, "expense": 9994}
misc = _line(out, "잡재료")
assert misc["prices"] == {"labor": 0, "material": 1234.5, "expense": 0}
assert misc["amounts"]["material"] == 2469.0
block = out["daega_blocks"][0]
assert block["blank"] == 0 and out["gaps"] == [] # 빈칸 규칙에 안 걸림
assert daega_price(out, "pipe@100.0")["sum"] == block["sum"] is not None
def test_B09_노임_새_판_이은_단가만_따라감():
old = compute_labor(_fixed_blocks(), b145.SHEETS, {})
sheets = copy.deepcopy(b145.SHEETS)
for row in sheets["labor"]:
row["price"] = round(row["price"] * 1.05)
new = compute_labor(_fixed_blocks(), sheets, {})
assert _line(new, "석공")["prices"]["labor"] == round(258935 * 1.05)
assert _line(new, "석공")["qty"] == _line(old, "석공")["qty"] == 0.2 # 품 그대로
for name in ("파형강관", "굴착기", "잡재료"):
assert _line(new, name)["prices"] == _line(old, name)["prices"]
def test_B09_덮개도_고정_줄에_먹음():
cover = {"S:f": {"fixed:잡재료#0": {"qty": 3, "material": 1000}}}
out = compute_labor(_fixed_blocks(), b145.SHEETS, {}, cover)
misc = _line(out, "잡재료")
assert misc["qty"] == 3 and misc["prices"]["material"] == 1000
assert misc["base"] == {"qty": 2, "labor": 0, "material": 1234.5, "expense": 0}
assert out["daega_orphans"] == []
@pytest.mark.parametrize("cover", [None, {"S:f": {"fixed:석공#0": {"labor": 1}}}])
def test_B09_거울_파이썬_TS(cover):
daega = _fixed_blocks()
py = json.loads(json.dumps(compute_labor(daega, b145.SHEETS, {}, cover), ensure_ascii=False))
ts = b145._ts(daega, b145.SHEETS, {}, cover)
assert b145._same(py, ts["out"])
assert b145._same(daega_price(py, "pipe@100.0"), ts["price"])
# ── 사본 → 대가 블록 → 내역 · 원가 · 집계표 한 바퀴 ─────────────────────────────
def _snap(root, owner, key, lines):
folder = snapshots.structures_dir(root) / snapshots.folder_name(owner)
folder.mkdir(parents=True)
def write(name, data):
(folder / name).write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
doc = labor.clean({"단위": "m", "담은로직": lines})
codes = [one["로직"] for one in lines if "로직" in one]
write(snapshots.MANIFEST_NAME, {"원본": {**b145._item(key), "경로": ["기슭막이", key]}})
write("단가.json", item_prices.to_json(item_prices.collect(codes, fixed.link_keys(doc))))
write("일위대가.json", {"줄": doc})
write("입력값.json", b145._values(b145.STONE))
def test_한_바퀴_사본_고정_줄_원가_빈칸_0_집계표(tmp_path):
from B09_Estimation.B09_Estimation_Router import compute_sheets
root = b145._project(tmp_path / "loop", [(100, "SS000901")])
lines = [
{"로직": "GF000219", "승격": True, "수량": {"손": 1}}, # 품셈 줄(메쌓기)
{"고정": _fx("석공", {"노무비": 1}, {"노임": LB}), "수량": {"손": 0.5}}, # 이은 노임
{"고정": _fx("잡재료", {"재료비": 1000}, unit="식"), "수량": {"손": 1}}, # 손 단가
]
_snap(root, "pipe@100.0", "SS000901", lines)
keys = linked_resource_keys(root)
assert LB in keys # 단가 책 수요에 이음 키
inputs = prices.build_inputs(None, keys)
inputs["daega"] = daega_inputs(root)
inputs["hopyo"] = {}
inputs["bill"] = {
"items": [
{"key": "st:revet", "section": "2.1", "name": "돌기슭막이", "spec": "", "unit": "m",
"qty": 10, "ref": {"tab": "dg_list", "key": "revet"}, "note": "",
"owners": {"pipe@100.0": 10}},
]
} # fmt: skip
sheets = compute_sheets(root, inputs, {})
combo = next(b for b in sheets["daega_blocks"] if b["kind"] == "조합")
kinds = [ln["kind"] for ln in combo["lines"]]
assert kinds == ["daega", "fixed", "fixed"] and combo["blank"] == 0
stone = combo["lines"][1]
book = {r["key"]: r for r in sheets["labor"]}
assert stone["prices"]["labor"] == book[LB]["price"] is not None
assert sheets["bill"]["totals"]["direct"]["blank"] == 0 # 원가계산서 빈 줄 0
assert sheets["bill"]["sums"]["material"] > 0
summary = compute_summary(sheets, hopyo_lines(sheets))
labor_qty = {r["key"]: r["qty"] for r in summary["sum_labor"]}
assert labor_qty[LB] >= 10 * 0.5 # 이은 고정 줄 = 노임 자원으로 셈
assert summary["fixed"] == 1 # 손 단가 줄 = 집계에서 빠짐 1
def test_사본_재적용_업데이트_고정_줄_그대로(tmp_path):
"""[업데이트](703-3) = 단가 책만 새로 — 고정 줄 품 · 손 단가 그대로 · 이은 단가만 새 판."""
root = b145._project(tmp_path / "upd", [(100, "SS000901")])
lines = [
{"고정": _fx("석공", {"노무비": 1}, {"노임": LB}), "수량": {"손": 0.5}},
{"고정": _fx("잡재료", {"재료비": 1000}, unit="식"), "수량": {"손": 1}},
]
_snap(root, "pipe@100.0", "SS000901", lines)
daega = daega_inputs(root)
book = prices.build_inputs(None, linked_resource_keys(root))
rows = [{**r, "price": 100} if r["key"] == LB else r for r in book["labor"]]
first = compute_labor(daega, {**b145.SHEETS, "labor": rows}, {})
again = daega_inputs(root) # 사본 다시 읽음(재적용 뒤 꼴 = 같은 원본)
second = compute_labor(again, {**b145.SHEETS, "labor": [{**r, "price": 200} for r in rows]}, {})
a, b = first["daega_blocks"][0]["lines"], second["daega_blocks"][0]["lines"]
assert [ln["qty"] for ln in a] == [ln["qty"] for ln in b] == [0.5, 1]
assert (a[0]["prices"]["labor"], b[0]["prices"]["labor"]) == (100, 200)
assert a[1]["prices"] == b[1]["prices"] == {"labor": 0, "material": 1000, "expense": 0}