"""B08 → B09 내역 받는 문 — 이름이 아니라 코드로 잇기 (2026-09-13, PLAN 6장 첫 일감 ①). 겨누는 것 ① 운반 줄 단가는 **그 줄로 선 내역 줄**에서 — 이름이 같은 줄(도자운반 토사·리핑암)이 둘이어도 첫 줄 단가가 둘째에 안 붙음(종전 `row.name == item.name` 실결함) ② 총 절취량은 **코드**(9-3·9-4·9-5)로 셈 — 줄 이름에 「깎기」가 없어도 검산이 돎 """ from __future__ import annotations from decimal import Decimal from functools import lru_cache import pytest import B09_Estimation.B09_Estimation_BillOfQuantities as bill_module from B09_Estimation.B09_Estimation_BillOfQuantities import build_bill from B09_Estimation.B09_Estimation_UnitPrice import build_unit_prices @lru_cache(maxsize=1) def _build(): return build_unit_prices() def _row(code: str, name: str, quantity: float, **extra) -> dict: return {"work_item_code": code, "name": name, "unit": "㎥", "quantity": quantity, **extra} def test_운반_줄_단가는_이름이_아니라_그_줄에서_읽는다(monkeypatch: pytest.MonkeyPatch) -> None: seen: list[list[dict]] = [] monkeypatch.setattr( bill_module, "check_free_haul_not_priced", lambda haul_rows: seen.append(haul_rows) ) payload = { "work_items": [ _row("FP-10-11", "dozer 운반", 10, haul_equipment="dozer", variant_value="토사"), # 같은 이름 · 표에 없는 갈래라 단가가 안 섬. _row("FP-10-11", "dozer 운반", 4, haul_equipment="dozer", variant_value="없는갈래"), ], "materials": [], } bill = build_bill(payload, build=_build()) priced = [r for r in bill.rows if not r.is_group] assert priced[0].unit_price_krw and priced[0].unit_price_krw > 0 assert priced[1].unit_price_krw is None prices = [row["unit_price_krw"] for row in seen[0]] assert prices == [priced[0].unit_price_krw, Decimal(0)] # 종전엔 둘 다 첫 줄 단가 def test_총_절취량은_코드로_센다(monkeypatch: pytest.MonkeyPatch) -> None: calls: list[dict] = [] monkeypatch.setattr( bill_module, "check_haul_volume_within_cut", lambda **kwargs: calls.append(kwargs) ) payload = { "work_items": [ # 이름에 「깎기」가 없음(마스터 표기 「토사깍기」) — 코드로만 절취임을 앎. _row("FP-09-03-02", "토사깍기", 10), _row("FP-09-12-01", "측구터파기", 3), # 절취 셈에 안 듦(종전과 같음) _row("FP-10-11", "dozer 운반", 5, haul_equipment="dozer", variant_value="토사"), ], "materials": [], } build_bill(payload, build=_build()) assert calls and calls[0]["total_cut_volume_m3"] == Decimal(10) assert calls[0]["haul_volume_total_m3"] == Decimal(5)