diff --git a/B02_ProjRegister/B02_ProjRegister_Repository.py b/B02_ProjRegister/B02_ProjRegister_Repository.py index 4714daa9..7eedccca 100644 --- a/B02_ProjRegister/B02_ProjRegister_Repository.py +++ b/B02_ProjRegister/B02_ProjRegister_Repository.py @@ -2,6 +2,7 @@ from __future__ import annotations +import logging from datetime import datetime from pathlib import Path from typing import Any @@ -16,6 +17,9 @@ from common_util.common_util_workflow import load_project_workflow from common_util.common_util_workflow_state import initialize_project_stages from config.config_db import get_db_pool from config.config_system import STORAGE_BASE_DIR +from M02_MasterTemplete.M02_Template_Layers import seed_project + +logger = logging.getLogger(__name__) def _build_project_storage(company_id: int, user_id: int, project_id: str) -> tuple[str, Path]: @@ -40,6 +44,12 @@ def _initialize_project_storage(project_root: Path, project_id: str) -> None: "stages": [f"{stage}/{subdir}" for stage, subdir in PROJECT_STORAGE_LAYOUT_V2], }, ) + # 마스터 템플릿 — 시스템 양식 전부를 작업본 + `_initial/` 로(회사 공식이 있어도 시스템). + # 복사가 실패해도 프로젝트는 만듦 — 읽는 쪽이 시스템 양식으로 떨어짐. + try: + seed_project(project_root) + except OSError: + logger.exception("프로젝트 양식 복사 실패: project_id=%s", project_id) async def create_project( diff --git a/resources/tester/test_m02_template_layers.py b/resources/tester/test_m02_template_layers.py index 1951b72b..c8a5f125 100644 --- a/resources/tester/test_m02_template_layers.py +++ b/resources/tester/test_m02_template_layers.py @@ -208,3 +208,15 @@ def test_채운_표는_작업본을_채워_돌려주고_저장_안_함( assert row["값"]["sta"] == "NO.2" and row["값"]["pp_len|파형강관|1000"] == 12 assert got["결과"] == {"계산": {}} and got["판"] == before assert layers.version_of(root / "templates/table/구조물집계표.json") == before + + +def test_프로젝트_만들기_자리에서_시스템_양식을_복사(world: dict[str, Any], tmp_path: Path) -> None: + from B02_ProjRegister.B02_ProjRegister_Repository import _initialize_project_storage + + layers.write_template(layers.company_dir(7), "table", "구조물집계표", {"회사": 1}) + root = tmp_path / "new_project" + _initialize_project_storage(root, "new") + got = layers.read_template(root / "templates", "table", "구조물집계표") + assert got["문서"] == {"판": 1, "열": []} # 회사 공식이 있어도 시스템 + assert (root / "templates/_initial/drawing/A1_도각.json").is_file() + assert (root / "project_manifest.json").is_file()