Files
Aislo/B09_Estimation/B09_Estimation_Router_Progress.py
T
eomsangdonandClaude Opus 5 1edde503fe feat(b09): 기성 단계 1벌 — 금회직접공사비 × 계약잡비율 · 계약/전회/금회/누계와 각 율 · 부가세 넷
- 계약내역·계약 원가계산서(같은 엔진에 계약 직접비)를 읽기만 해 파생 — 계약 불변
- 제잡비 줄마다 계약잡비율 = 도급액 ÷ 계약 직접공사비 (구조로 읽음, 확인 대기)
- 회차 목록 저장 · 기성(%) · 잔량 · 계약 수량 넘으면 알림
- 부가세: 직접입력 / 공급가액 / 재료비 / 재료비+산출경비 (설계 vat_base 같이 씀)
- 원가계산서 조립·계약본 받기 조각을 떼어 기성이 같은 길로 받음
- 기성 탭 파일 · 사전 키(등록은 서브) · 시험 6건 · 전체 1717 통과

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BW6Jdsh18WPtYUR6THZJqn
2026-09-14 06:03:22 +09:00

89 lines
3.7 KiB
Python

"""B09 기성 단계 탭 API — 계약내역 → 기성내역 · 기성 제잡비 계산서 (PLAN 12장 · 랩탑 메인).
⚠ 계약내역(`contract_for`)과 계약 원가계산서(`cost_from_bill` 에 계약 직접비)를 **읽기만** 한다.
저장은 `estimation.progress` 한 칸(회차 목록) — 설계·계약·원가계산서 저장본은 안 건드린다.
"""
from __future__ import annotations
import logging
from decimal import Decimal
from typing import Any
from uuid import UUID
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from B09_Estimation.B09_Estimation_Progress import (
SETTINGS_KEY,
VAT_CHOICES,
clean_settings,
progress_sheet,
)
from B09_Estimation.B09_Estimation_Rates import RateLookupError
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api/projects", tags=["B09 Estimation — Progress"])
@router.get("/{project_id}/estimation/progress")
async def get_progress(project_id: UUID, round: int | None = None) -> JSONResponse:
"""기성 한 장 — `round` 회차(1부터)를 금회로 · 없으면 마지막 회차."""
from B09_Estimation.B09_Estimation_Router_Contract import contract_for
from B09_Estimation.B09_Estimation_Router_CostSheet import cost_from_bill
from common_util.common_util_project_settings import estimation_settings
found = await contract_for(project_id)
if isinstance(found, JSONResponse):
return found
root, bill, _, contract = found
totals = contract["totals"]["contract"]
direct = {part: Decimal(totals[f"{part}_krw"]) for part in ("material", "labor", "expense")}
try:
cost_data, cost_result, _ = cost_from_bill(root, bill, direct)
except RateLookupError as error:
return JSONResponse(status_code=422, content={"status": "error", "message": str(error)})
stored, _ = clean_settings(dict(estimation_settings(root).get(SETTINGS_KEY) or {}))
sheet = progress_sheet(contract["rows"], cost_data, cost_result, stored, round)
return JSONResponse(
content={
"status": "success",
**sheet,
"settings": stored,
"fields": {"vat": [{"key": k, "label": label} for k, label in VAT_CHOICES]},
"limit_note": (
"기성 표본 0건 — 구조가 서는지까지만 확인됨 · 계약잡비율(도급액 ÷ 계약 직접공사비)·"
"회차별 절사는 구조로 읽음 · 사정·절사 선택 미구현"
),
}
)
@router.put("/{project_id}/estimation/progress")
async def put_progress(project_id: UUID, body: dict[str, Any]) -> JSONResponse:
"""회차 목록 저장 — 틀린 칸이 있으면 아무것도 안 저장."""
from B09_Estimation.B09_Estimation_Router import _project_root_of
from common_util.common_util_project_settings import save_section
root = await _project_root_of(project_id)
if root is None:
return JSONResponse(
status_code=404,
content={"status": "error", "message": "프로젝트 저장 폴더를 찾지 못했습니다."},
)
cleaned, errors = clean_settings(body)
if errors:
return JSONResponse(
status_code=400,
content={"status": "error", "message": " · ".join(errors), "errors": errors},
)
try:
save_section(root, "estimation", {SETTINGS_KEY: cleaned}, replace_keys=(SETTINGS_KEY,))
except Exception:
logger.exception("B09 기성 저장 실패: project_id=%s", project_id)
return JSONResponse(
status_code=500,
content={"status": "error", "message": "기성 회차를 저장하지 못했습니다."},
)
return JSONResponse(content={"status": "success", "settings": cleaned})