From fdb3eb9b77c58c613f83844f339d8c9c4f83f05c Mon Sep 17 00:00:00 2001 From: umsangdon Date: Sat, 31 Oct 2026 14:59:58 +0900 Subject: [PATCH] =?UTF-8?q?feat(B09):=20=EC=98=A4=EB=A5=B8=EC=AA=BD=20?= =?UTF-8?q?=EC=9E=AC=EB=A3=8C=20=EC=B0=BD=EA=B3=A0=20=C2=B7=20=EC=A7=80?= =?UTF-8?q?=EB=82=9C=20=EA=B3=B5=EC=82=AC=20=EC=9D=BC=EC=9C=84=EB=8C=80?= =?UTF-8?q?=EA=B0=80=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0(PLAN=20703-1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 설계내역서 표 오른쪽 서랍(공용 side_panels · 접고 펴기 · 좁은 화면 = 아래) — 찾기 하나 + 출처 탭 이 공사 · 내 것 · 회사 · 품셈(704-1 기준 목록 · 우클릭 계산서 보기) · 지난 공사 - 두 번 누름 · Enter = 고른 내역 줄에 단가연결 · 끌어 놓기 = 놓은 줄 · 연결 = 단가연결 모달과 같은 길(702-3 즉시 금액) - 품셈 = 넣을 값 창에 계산서 입력 전부(목록 바꿈은 기본과 다른 것만 — 석축헐기 뒷길이 60 이 0 으로 열리던 것) - 서버 B09_Estimation_Past + GET/POST /estimation/past — 같은 회사 다른 공사 구조물 사본 · 서고 사본 → 이 공사 서고 사본(폴더 통째 · 가져온곳 · 덮개째 · 단가 = 이 공사 책) · 남의 회사 403 - 표 높이 셈(spaceBelow)이 뒤 형제만 보므로 서랍 = DOM 앞 · CSS order 로 오른쪽 - 시험 test_703_1 6 · 셸 꼴 글 시험 200-2 · 202-1 = 표 칸 + 서랍 꼴로 고침(낡은 글) Co-Authored-By: Claude Opus 5.5 --- B09_Estimation/B09_Estimation_Past.py | 139 +++++++ B09_Estimation/B09_Estimation_Router.py | 66 ++++ B09_Estimation/B09_Estimation_UI_Page.css | 27 ++ B09_Estimation/B09_Estimation_UI_Shell.ts | 8 +- B09_Estimation/B09_Estimation_UI_Store.ts | 370 ++++++++++++++++++ B09_Estimation/B09_Estimation_UI_Tabs_Bill.ts | 3 + .../B09_Estimation_UI_Tabs_Bill_Edit.ts | 6 + .../B09_Estimation_UI_Tabs_Bill_Level.ts | 3 + .../tester/test_200_2_b09_bill_level_bar.py | 6 +- .../tester/test_202_1_table_hint_bottom.py | 4 +- resources/tester/test_703_1_b09_past.py | 147 +++++++ 11 files changed, 774 insertions(+), 5 deletions(-) create mode 100644 B09_Estimation/B09_Estimation_Past.py create mode 100644 B09_Estimation/B09_Estimation_UI_Store.ts create mode 100644 resources/tester/test_703_1_b09_past.py diff --git a/B09_Estimation/B09_Estimation_Past.py b/B09_Estimation/B09_Estimation_Past.py new file mode 100644 index 000000000..96973070c --- /dev/null +++ b/B09_Estimation/B09_Estimation_Past.py @@ -0,0 +1,139 @@ +"""B09 재료 창고 「지난 공사」(PLAN 703-1) — 같은 회사 다른 공사 일위대가 → 이 공사 서고 사본. + +목록 = 그 공사 구조물 사본(`S:` · 일위대가 있는 것) · 서고 사본(`L:` · 사전조합 · 구조물조합) · + 고친 칸 수 = 그 공사 저장 덮개(블록 cover — 조합 `S:`/`L:폴더` · 사전조합 `C:참조` · 짝 + `Labor_Source.Builder`) · 같은 원본 · 같은 값 · 같은 덮개 = 한 줄 +가져옴 = 사본 폴더 통째 → 이 공사 `library/{종류}@{층}@{주인}@{키}~{공사 · 사본 해시}`(구조물 사본 = + 서고 구조물조합과 한 꼴) · manifest `가져온곳` = 그 공사 · 사본 · 다시 고르면 같은 사본 · + 덮개 = 그 공사 저장 칸 + 이 공사 블록 cover(조합 = `L:새 폴더` · 사전조합 = 같은 `C:참조`) → + 화면 캐시가 그 cover 가 비었을 때만 얹음([저장] 때 남음) · + 단가 = 이 공사 단가 책(셈이 이 공사 것) · 권한 = 부르는 쪽(같은 회사). +""" + +from __future__ import annotations + +import shutil +from pathlib import Path +from typing import Any + +from B09_Estimation import B09_Estimation_Bill_Library as library +from B09_Estimation import B09_Estimation_Store as store +from common_util.common_util_json import atomic_write_json +from M02_MasterTemplete import M02_Labor_Ref as refs +from M02_MasterTemplete.M02_Item_Snapshot import ( + FOLDER_PATTERN, + MANIFEST_NAME, + PICKS_FILE, + VALUES_FILE, + linked_snapshots, + now_text, + structures_dir, +) +from M02_MasterTemplete.M02_Item_Source import LABOR_FILE, read_json + + +def _covers(root: Path) -> dict[str, Any]: + return store.read_user(root).get("daega_cover") or {} + + +def _cells(cover: Any) -> dict[str, Any]: + """덮개 칸만(복사본 표지 `@copy` 뺌).""" + return {k: v for k, v in (cover or {}).items() if not k.startswith("@")} + + +def cover_of(head: str, folder: Path, kind: str) -> str: + """사본 폴더의 대가 블록 cover — 사전조합 = 참조(공사 안 같은 사전조합 한 덮개).""" + if kind != "precombo": + return f"{head}:{folder.name}" + ref = ((read_json(folder / MANIFEST_NAME) or {}).get("원본") or {}).get("참조") or {} + return f"C:{refs.ref_id(ref)}" + + +def _row(folder: Path, key: str, kind: str, cover: dict[str, Any]) -> dict[str, Any]: + manifest = read_json(folder / MANIFEST_NAME) or {} + origin = manifest.get("원본") or {} + path = origin.get("경로") or [] + if kind == "precombo": + name, spec, unit = origin.get("name") or folder.name, "", origin.get("단위") or "" + else: # 짝 `Labor_Source.Builder.combo` 이름 · 규격 · 단위 + labor = read_json(folder / LABOR_FILE) or {} + name = origin.get("name") or " ".join(path) or folder.name + spec, unit = " › ".join(path), (labor.get("줄") or {}).get("단위") or "" + cells = _cells(cover.get(cover_of(key[0], folder, kind))) + sig = library.tag( + { + "원본": {k: origin.get(k) for k in ("layer", "owner", "key", "참조")}, + "값": [read_json(folder / f) for f in (VALUES_FILE, PICKS_FILE)], + "덮개": cells, + } + ) + kind_text = "사전조합" if kind == "precombo" else "구조물 조합" + return {"cover": key, "name": name, "spec": spec, "unit": unit, "kind": kind_text, + "covers": len(cells), "sig": sig} # fmt: skip + + +def rows_of(root: str | Path) -> list[dict[str, Any]]: + """한 공사 가져올 일위대가 — 구조물 사본 → 서고 사본 · 같은 것 한 줄.""" + root = Path(root) + cover = _covers(root) + out: list[dict[str, Any]] = [] + for info in sorted(linked_snapshots(root).values(), key=lambda i: i["폴더"]): + if "일위대가" in info.get("부분", []): + folder = structures_dir(root) / info["폴더"] + out.append(_row(folder, f"S:{folder.name}", "combo", cover)) + for folder, manifest in library.copies(root): + out.append(_row(folder, f"L:{folder.name}", str(manifest.get("종류")), cover)) + seen: set[str] = set() + return [r for r in out if not (r["sig"] in seen or seen.add(r["sig"]))] + + +def _source(other: Path, cover_key: str) -> tuple[Path, str, str, str | None, str]: + """덮개 열쇠 → (사본 폴더, 종류, 층, 주인, 키) · 틀린 모양 ValueError · 없음 LookupError.""" + head, _, rest = cover_key.partition(":") + if head == "S" and FOLDER_PATTERN.match(rest): + folder = structures_dir(other) / rest + origin = (read_json(folder / MANIFEST_NAME) or {}).get("원본") or {} + kind, layer, owner, key = ( + "combo", + origin.get("layer"), + origin.get("owner"), + origin.get("key"), + ) + elif head == "L" and library.NAME.match(rest): + folder = library.library_dir(other) / rest + kind, layer, owner, key = rest.split("~")[0].split("@") + owner = None if owner == "-" else owner.replace("-", "/") + else: + raise ValueError(f"가져올 일위대가 모양이 틀림 「{cover_key}」") + if not isinstance(read_json(folder / MANIFEST_NAME), dict) or not layer or not key: + raise LookupError(f"지난 공사에 그 일위대가가 없음 「{cover_key}」") + return folder, kind, str(layer), owner, str(key) + + +def import_past( + root: str | Path, + other: str | Path, + other_ref: dict[str, Any], + cover_key: str, + who: dict[str, Any] | None = None, +) -> dict[str, Any]: + """지난 공사 사본 하나 → 이 공사 서고 사본 — `{폴더, 만듦, 덮개, 덮개자리}` · + 덮개 = 그 공사 저장 칸 · 덮개자리 = 이 공사 블록 cover.""" + src, kind, layer, owner, key = _source(Path(other), cover_key) + tag = {"공사": str(other_ref.get("project_id")), "사본": cover_key} + name = library.folder_name(kind, layer, owner, key, tag) + target = library.library_dir(root) / name + cells = _cells(_covers(Path(other)).get(cover_of(cover_key[0], src, kind))) + mine = cover_of("L", src, kind) if kind == "precombo" else f"L:{name}" + out = {"폴더": name, "덮개": cells, "덮개자리": mine} + if isinstance(read_json(target / MANIFEST_NAME), dict): + return {**out, "만듦": False} + if target.is_dir(): # 끊긴 쓰기(manifest 없음) 자리 + shutil.rmtree(target) + shutil.copytree(src, target, ignore=shutil.ignore_patterns(MANIFEST_NAME)) + old = read_json(src / MANIFEST_NAME) or {} + manifest = {k: old[k] for k in ("원본", "값", "원값") if k in old} + manifest.update({"종류": kind, "가져온날": now_text(), "가져온이": who}) + manifest["가져온곳"] = {**other_ref, "사본": cover_key} + atomic_write_json(target / MANIFEST_NAME, manifest) # 마지막 — 있으면 다 쓴 폴더 + return {**out, "만듦": True} diff --git a/B09_Estimation/B09_Estimation_Router.py b/B09_Estimation/B09_Estimation_Router.py index 96ca599a0..d15bd3353 100644 --- a/B09_Estimation/B09_Estimation_Router.py +++ b/B09_Estimation/B09_Estimation_Router.py @@ -35,6 +35,12 @@ 「내 자료집에 저장」(703-2) — 펼친 일위대가 → 개인 층 사전조합 (`B09_Estimation_Daega_Personal`) · user = 화면 캐시 덮개 · 같은 이름 = 409 {같은이름} → 덮어쓰기(overwrite = 키) · 새 이름 + GET /api/projects/{id}/estimation/past + 재료 창고 「지난 공사」(703-1) — 같은 회사 다른 공사의 일위대가 목록(`B09_Estimation_Past`) + POST /api/projects/{id}/estimation/past {project_id, cover} + 지난 공사 일위대가 → 이 공사 서고 사본(덮개째) → {폴더, 만듦, key, cover, 덮개, payload} · + 덮개 = 그 공사 저장 칸(화면 캐시 cover 가 비었을 때만 얹음 · 같은 꼴 블록이 먼저 있으면 빈 것) · + 같은 회사만(남의 회사 403) 운반 사본 연결 = 셈 때마다 거리로 사본 다시 고름(`Bill_Library.resolve_hauls` · `fix_keys`). 저장 자리 = 프로젝트 안 `B09_Estimation/v1/`(`B09_Estimation_Store`) · @@ -66,6 +72,7 @@ from B08_Quantity.B08_Quantity_Router_Milestone import read_data as read_milesto from B08_Quantity.B08_Quantity_Router_Milestone import site_info from B09_Estimation import B09_Estimation_Bill_Library as library from B09_Estimation import B09_Estimation_Daega_Personal as personal +from B09_Estimation import B09_Estimation_Past as past from B09_Estimation import B09_Estimation_Prices as prices from B09_Estimation import B09_Estimation_Refresh as refresh from B09_Estimation import B09_Estimation_Sangeun as sangeun @@ -82,10 +89,12 @@ from B09_Estimation.B09_Estimation_Router_Quotes import router as quotes_router from B09_Estimation.B09_Estimation_Summary import compute_summary, hopyo_lines, used_materials from common_util.common_util_auth import verify_session from common_util.common_util_project_settings import reset_section +from common_util.common_util_storage import resolve_stored_project_path from common_util.common_util_workflow_state import mark_stage from M02_MasterTemplete import M02_Layer_Access as access from M02_MasterTemplete.M02_Item_Snapshot import importer from M02_MasterTemplete.M02_MasterTemplete_Router_Items import _call, _root +from M02_MasterTemplete.M02_MasterTemplete_Router_Layers import _company_projects, _project try: # 252 공기 초안(draft 폴더 · 지우면 공기 탭 원천 없이) from B09_Estimation.draft import B09_Draft_Schedule_Source as schedule_draft @@ -488,6 +497,63 @@ async def save_personal( } +def _past_rows(projects: list[dict[str, Any]], here: str) -> list[dict[str, Any]]: + out = [] + for other in projects: + if other["project_id"] == here or not other.get("storage_path"): + continue + try: + rows = past.rows_of(Path(resolve_stored_project_path(other["storage_path"]))) + except (ValueError, OSError): # 못 읽는 공사 = 건너뜀 + continue + ref = {"project_id": other["project_id"], "project": other["name"]} + out += [{**ref, **row} for row in rows] + return out + + +@router.get("/{project_id}/estimation/past") +async def past_list( + project_id: UUID, session: dict[str, Any] = Depends(verify_session) +) -> dict[str, Any]: + here = await _project(session, str(project_id)) + projects = await _company_projects(int(here["company_id"])) + return {"rows": await asyncio.to_thread(_past_rows, projects, str(project_id))} + + +class PastBody(BaseModel): + project_id: str = Field(min_length=1, max_length=64) + cover: str = Field(min_length=3, max_length=200) + + +@router.post("/{project_id}/estimation/past") +async def past_import( + project_id: UUID, body: PastBody, session: dict[str, Any] = Depends(verify_session) +) -> dict[str, Any]: + here = await _project(session, str(project_id)) + if body.project_id == str(project_id): + raise HTTPException(status_code=400, detail="이 공사 것은 「이 공사」 탭에서 고름") + other = await _project(session, body.project_id) + if other["company_id"] != here["company_id"]: + raise HTTPException(status_code=403, detail="같은 회사 공사에서만 가져옴") + ref = {"project_id": body.project_id, "프로젝트": other.get("name")} + try: + made = await asyncio.to_thread( + past.import_past, here["root"], other["root"], ref, body.cover, importer(session) + ) + except LookupError as error: + raise HTTPException(status_code=404, detail=str(error)) from error + except ValueError as error: + raise HTTPException(status_code=400, detail=str(error)) from error + out = await payload(project_id, here["root"]) + daega = out["inputs"].get("daega") or {} + key = (daega.get("libs") or {}).get(made["폴더"]) + # 같은 꼴 블록이 이 공사에 먼저 있으면 그 블록(다른 cover) — 덮개 안 옮김(그 블록 덮개 그대로) + cover = next((b["cover"] for b in daega.get("blocks") or [] if b["id"] == key), None) + if cover != made.pop("덮개자리"): + made["덮개"] = {} + return {**made, "key": key, "cover": cover, "payload": out} + + # 166-4 견적서 파일 길 — 같은 머리 · 같은 권한 router.include_router(quotes_router) diff --git a/B09_Estimation/B09_Estimation_UI_Page.css b/B09_Estimation/B09_Estimation_UI_Page.css index 82bc79315..88d873c46 100644 --- a/B09_Estimation/B09_Estimation_UI_Page.css +++ b/B09_Estimation/B09_Estimation_UI_Page.css @@ -274,3 +274,30 @@ html.is-bm-route .b09-estimation > .b09-estimation__tabs:first-child { .b09-popup .ui-data-table { max-height: none; } + +/* 703-1 재료 창고 — 오른쪽 서랍 몸(탭 · 찾기 목록 · 안내) 세로 쌓음 · 목록만 스크롤 */ +.b09-store { + display: flex; + flex-direction: column; + gap: var(--spacing-8); + height: 100%; + min-height: 0; +} + +.b09-store .ui-find { + flex: 1 1 auto; + min-height: 0; +} + +/* 703-1 표 칸 + 오른쪽 창고 — 창고가 DOM 앞(표 높이 셈) · 보이는 차례는 표 먼저 */ +.b09-estimation__work { + display: flex; + flex: 1 1 auto; + flex-direction: column; + order: -1; + min-width: 0; +} + +.ui-side-panels-row > .ui-side-panels.b09-store__side { + flex: none; +} diff --git a/B09_Estimation/B09_Estimation_UI_Shell.ts b/B09_Estimation/B09_Estimation_UI_Shell.ts index b1550bc15..a315898fa 100644 --- a/B09_Estimation/B09_Estimation_UI_Shell.ts +++ b/B09_Estimation/B09_Estimation_UI_Shell.ts @@ -19,6 +19,7 @@ import { createText } from "@ui/ui_template_text"; import { createBanner } from "@ui/ui_template_banner"; import { createButton, + el, hideLoadingOverlay, showConfirmDialog, showLoadingOverlay, @@ -290,7 +291,12 @@ export function renderB09Estimation(root: HTMLElement): void { const fold = bill?.fold?.(table.root); // 702-1 줄 펼침 = 표 아래 // 701-3 띠(원가계산서 「빈 줄 n · 미완성」) = 표 위 const banner = spec.banner ? [createBanner({ tone: "warning", text: spec.banner })] : []; - panel.replaceChildren(...banner, table.root, ...(fold ? [fold] : []), ...(foot ? [foot] : [])); + const body = [table.root, ...(fold ? [fold] : []), ...(foot ? [foot] : [])]; + const side = bill?.side?.(table.root); // 703-1 재료 창고 = 표 오른쪽 서랍 + const main = side ? el("div", { className: "b09-estimation__work", children: body }) : null; + // 서랍 = DOM 앞(표 높이 셈 `spaceBelow` 가 뒤 형제만 봄) · 보이는 차례 = CSS order + const row = main && el("div", { className: "ui-side-panels-row", children: [side!, main] }); + panel.replaceChildren(...banner, ...(row ? [row] : body)); if (at >= 0) requestAnimationFrame(() => table.focusRow(at, false)); // 스크롤만(표시 = 빨강) }; diff --git a/B09_Estimation/B09_Estimation_UI_Store.ts b/B09_Estimation/B09_Estimation_UI_Store.ts new file mode 100644 index 000000000..81c62c5c6 --- /dev/null +++ b/B09_Estimation/B09_Estimation_UI_Store.ts @@ -0,0 +1,370 @@ +/* ============================================================================= + * B09_Estimation_UI_Store.ts + * B09 설계내역서 오른쪽 재료 창고(PLAN 703-1) — 찾기 하나 + 출처 탭(이 공사 · 내 것 · 회사 · 품셈 · 지난 공사). + * + * 두 번 누름 · Enter = 고른 내역 줄(`…_Bill_Level` 고름)에 단가연결 · 끌어 놓기 = 놓은 줄에 단가연결 · + * 우클릭 = [고른 줄에 연결] · 품셈 = [계산서 보기](704-2 `Labor_Sheet` · [담기] = 연결) + * 연결 = 단가연결 모달과 같은 길(`…_Bill_Link` · 702-3 즉시 금액) — 호표 = 연결 · 조합 · 사전조합 = 사본 들여옴 · + * 품셈 = 넣을 값 창(대표 규격 채움) · 지난 공사 = 서버가 이 공사 서고 사본으로(`…_Past` · 덮개째 · + * 단가 = 이 공사 단가 책) → 받은 덮개를 그 cover 가 비었을 때만 화면 캐시에 얹음 + * 틀 = 공용 오른쪽 서랍(`ui_template_side_panels` · 접고 펴기 · 폭 끌기 · 좁은 화면 = 아래로) + * 창고 하나 = 페이지 한 벌(다시 그려도 찾기 글 · 탭 · 받은 목록 남음) · 이 공사 = 그릴 때마다 새로 + * ========================================================================== */ + +import { API_BASE_URL } from "@config/config_frontend"; +import type { DataRow } from "@ui/ui_template_data_table"; +import { el, showToast } from "@ui/ui_template_elements"; +import { createFindList, type FindRow } from "@ui/ui_template_find_list"; +import { loadRows } from "@ui/ui_template_item_picker"; +import { itemName } from "@ui/ui_template_item_picker_data"; +import { matchLogic } from "@ui/ui_template_logic_find"; +import { createSidePanels } from "@ui/ui_template_side_panels"; +import { createTabs } from "@ui/ui_template_tabs"; +import { createText } from "@ui/ui_template_text"; +import { currentProjectId } from "../A00_Common/b_project_switch"; +import { fetchSessionUser } from "../A06_Login/A06_Login_Api_Fetch"; +import { + fetchLibrary, + fetchStandard, + fetchStandardSheet, + type StandardRow, +} from "../M02_MasterTemplete/M02_MasterTemplete_Labor_Api"; +import { openStandardSheet } from "../M02_MasterTemplete/M02_MasterTemplete_Labor_Sheet"; +import { ownOwner } from "../M02_MasterTemplete/M02_MasterTemplete_Layer"; +import type { Row } from "./B09_Estimation_Calc_Base"; +import type { TabContext } from "./B09_Estimation_UI_Tabs"; +import { applyAt, openMenuAt } from "./B09_Estimation_UI_Tabs_Bill_Edit"; +import { askInputs, importLib, type ApplyRef } from "./B09_Estimation_UI_Tabs_Bill_Link"; +import { pickedKey } from "./B09_Estimation_UI_Tabs_Bill_Level"; + +type Source = "here" | "mine" | "company" | "poomsem" | "past"; +const SOURCES: Array<[Source, string]> = [ + ["here", "이 공사"], + ["mine", "내 것"], + ["company", "회사"], + ["poomsem", "품셈"], + ["past", "지난 공사"], +]; +/** 한 번에 그리는 줄 — 품셈 1만 줄 · 찾기로 좁힘 */ +const SHOWN = 200; +const DRAG = "text/x-b09-store"; + +interface Item { + tag: string; + name: string; + sub: string; + unit: string; + hit: (q: string) => boolean; + go: (ctx: TabContext, apply: ApplyRef) => void; + sheet?: (put: () => void) => void; +} + +const words = (q: string): string[] => q.toLowerCase().split(/\s+/).filter(Boolean); +const has = (text: string) => (q: string) => words(q).every((w) => text.toLowerCase().includes(w)); +const onPayload = (ctx: TabContext) => (p: Row) => Object.assign(ctx.payload, p); + +function hereItems(ctx: TabContext): Item[] { + const of = (tab: "dg" | "sg", list: Row[] | undefined): Item[] => + (list || []).map((r) => { + const tag = tab === "dg" ? `일위대가 ${r.no}호` : `단가산출 ${r.no}호`; + const name = String(r.name || ""); + return { + tag, + name, + sub: String(r.spec || ""), + unit: String(r.unit || ""), + hit: has(`${tag} ${name} ${r.spec || ""}`), + go: (_c, apply) => apply({ tab, key: r.key }, r), + }; + }); + return [...of("dg", ctx.sheets.daega), ...of("sg", ctx.sheets.sg_list)]; +} + +/** 내 것 · 회사 — 구조물 조합(그 층) + 사전조합(그 층 일위대가) */ +async function layerItems(layer: "personal" | "company"): Promise { + const owner = ownOwner(layer, await fetchSessionUser().catch(() => null)); + const combos = (await loadRows().catch(() => [])).filter((r) => r.layer === layer); + const pres = owner ? await fetchLibrary({ 층: layer, 주인: owner }, "precombo") : []; + return [ + ...combos.map((r) => { + const name = itemName(r); + const pick = { kind: "combo" as const, layer, owner: r.owner ?? null, key: r.key }; + return { + tag: "구조물 조합", + name, + sub: "", + unit: String(r.단위 || ""), + hit: has(`구조물 조합 ${name}`), + go: (ctx: TabContext, apply: ApplyRef) => + void importLib({ apply, onPayload: onPayload(ctx) }, pick), + }; + }), + ...pres.map((r) => { + const name = r.제목 || r.이름; + const pick = { kind: "precombo" as const, layer, owner, key: r.이름 }; + return { + tag: "일위대가", + name, + sub: [r.구분, r.상세구분].filter(Boolean).join(" "), + unit: String(r.단위 || ""), + hit: has(`일위대가 ${name} ${r.구분 ?? ""} ${r.상세구분 ?? ""}`), + go: (ctx: TabContext, apply: ApplyRef) => + void importLib({ apply, onPayload: onPayload(ctx) }, pick), + }; + }), + ]; +} + +/** 넣을 값 창 — 대표 규격 = 계산서(704-2)가 셈에 쓴 입력 전부(목록 `바꿈` 은 기본과 다른 것만 · + * 기본을 다르게 보는 칸이 빠짐 — 석축헐기 뒷길이 60 · 0) · 못 받으면 `바꿈` */ +function askStandard(apply: ApplyRef, r: StandardRow): void { + const open = (given: Row): void => askInputs(apply, r.키, r.이름, { given }); + fetchStandardSheet(r).then( + (sheet) => open((sheet as { 입력?: Row }).입력 ?? r.바꿈), + () => open(r.바꿈), + ); +} + +/** 품셈 = 704-1 기준 목록(품명 · 규격 · 금액 · 실무 낱말 찾기) · 연결 = 넣을 값 창(대표 규격 채움) */ +async function poomsemItems(): Promise { + const list = await fetchStandard(); + return list.줄.map((r) => ({ + tag: r.공종 || "품셈", + name: r.이름, + sub: [r.규격, r.금액 === null ? "" : `${Math.round(r.금액).toLocaleString("ko-KR")}원`] + .filter(Boolean) + .join(" · "), + unit: r.단위, + hit: (q) => !q || matchLogic(q, { ...r, 이름: `${r.이름} ${r.규격}` }).ok, + go: (_c, apply) => askStandard(apply, r), + sheet: (put) => openStandardSheet(r, put), + })); +} + +async function call(path: string, body?: Row): Promise { + const projectId = currentProjectId(); + if (!projectId) throw new Error("프로젝트 없음"); + const response = await fetch(`${API_BASE_URL}/projects/${projectId}/estimation/${path}`, { + method: body ? "POST" : "GET", + credentials: "include", + headers: { "Content-Type": "application/json" }, + ...(body && { body: JSON.stringify(body) }), + }); + const got = (await response.json().catch(() => null)) as Row | null; + if (!response.ok || !got) { + const detail = got?.detail; + throw new Error(typeof detail === "string" ? detail : `HTTP ${response.status}`); + } + return got; +} + +/** 지난 공사 가져옴 — 이 공사 서고 사본 · 덮개 = 그 cover 가 비었을 때만 얹음 */ +async function importPast(ctx: TabContext, apply: ApplyRef, r: Row): Promise { + showToast("지난 공사에서 가져오는 중…", "info"); + try { + const got = await call("past", { project_id: r.project_id, cover: r.cover }); + if (!got.key) throw new Error("사본은 들여왔으나 일위대가를 못 만듦"); + onPayload(ctx)(got.payload); + const from = ((got.payload.sheets?.daega as Row[]) || []).find((x) => x.key === got.key); + const cells: Row = got.덮개 || {}; + const n = Object.keys(cells).length; + let note = ""; + if (n && got.cover) { + const all: Row = { ...(ctx.user.daega_cover || {}) }; + if (Object.keys(all[got.cover] || {}).length) note = " · 이 공사에 고친 칸이 있어 그대로 둠"; + else { + all[got.cover] = cells; + ctx.user = { ...ctx.user, daega_cover: all }; // 아래 연결이 같은 캐시에 씀 + note = ` · 고친 칸 ${n} 함께 옮김`; + } + } + apply({ tab: "dg", key: got.key, lib: got.폴더 }, from); + showToast(`「${r.project}」 일위대가로 연결함${note} — [저장]해야 남음`, "success"); + } catch (error) { + showToast(`못 가져옴 — ${error instanceof Error ? error.message : error}`, "error"); + } +} + +async function pastItems(): Promise { + const got = await call("past"); + return ((got.rows as Row[]) || []).map((r) => ({ + tag: String(r.project || ""), + name: String(r.name || ""), + sub: [r.kind, r.covers ? `고친 칸 ${r.covers}` : ""].filter(Boolean).join(" · "), + unit: String(r.unit || ""), + hit: has(`${r.project} ${r.name} ${r.spec} ${r.kind}`), + go: (ctx, apply) => void importPast(ctx, apply, r), + })); +} + +const LOAD: Record, () => Promise> = { + mine: () => layerItems("personal"), + company: () => layerItems("company"), + poomsem: poomsemItems, + past: pastItems, +}; + +/** 페이지 한 벌 창고 */ +let store: { + root: HTMLElement; + bind: (ctx: TabContext, raw: DataRow[], table: HTMLElement) => void; +} | null = null; + +function makeStore(): NonNullable { + let ctx: TabContext | null = null; + let raw: DataRow[] = []; + let source: Source = "here"; + const got: Partial> = {}; + let shown: Item[] = []; + const finder = createFindList({ placeholder: "품명 · 규격 · 실무 낱말로 찾기" }); + const tabs = createTabs({ + tabs: SOURCES.map(([key, label]) => ({ key, label })), + value: source, + kind: "pill", + onChange: (key) => { + source = key as Source; + draw(); + }, + }); + const guide = createText( + "두 번 누름 = 고른 내역 줄에 단가연결 · 끌어서 내역 줄에 놓기 = 그 줄에 연결 · 우클릭 = 계산서 보기(품셈)", + ); + + /** 그 줄에 연결 — 줄 = 고른 내역 줄(index 없음) · 연결 못 하는 줄이면 알림 */ + const linkTo = (item: Item, at?: number): void => { + if (!ctx) return; + const key = pickedKey(); + const i = at ?? raw.findIndex((r) => String(r.key) === key); + const apply = i >= 0 ? applyAt(ctx, raw, i) : null; + if (!apply) + return void showToast("내역 항목 줄을 먼저 누름(자재 · 묶음 줄은 연결 없음)", "info"); + item.go(ctx, apply); + }; + + const draw = (): void => { + const now = source === "here" ? (ctx ? hereItems(ctx) : []) : got[source]; + if (source !== "here" && now === undefined) void load(source); + if (!Array.isArray(now)) { + finder.hint.textContent = now instanceof Error ? `못 읽음 — ${now.message}` : "읽는 중…"; + return finder.setRows([]); + } + const q = finder.search.value.trim(); + const found = now.filter((x) => x.hit(q)); + shown = found.slice(0, SHOWN); + const more = found.length > SHOWN ? ` · 앞 ${SHOWN} 줄만 — 찾기로 좁힘` : ""; + finder.hint.textContent = found.length + ? `${found.length} / ${now.length}${more}` + : now.length + ? "맞는 것 없음" + : source === "past" + ? "가져올 지난 공사 일위대가 없음(같은 회사 공사만)" + : "비었음"; + finder.setRows( + shown.map((x, i) => ({ + key: String(i), + tag: x.tag, + name: x.name, + sub: x.sub, + unit: x.unit, + onPick: () => linkTo(x), + })), + ); + for (const row of finder.root.querySelectorAll("[data-pick]")) { + row.draggable = true; + row.addEventListener("dragstart", (ev) => ev.dataTransfer?.setData(DRAG, row.dataset.pick!)); + } + for (const [key] of SOURCES) { + const list = key === "here" ? (ctx ? hereItems(ctx) : []) : got[key]; + tabs.setBadge(key, Array.isArray(list) ? list.length : 0); + } + }; + + const load = async (key: Exclude): Promise => { + got[key] = "loading"; + try { + got[key] = await LOAD[key](); + } catch (error) { + got[key] = error instanceof Error ? error : new Error(String(error)); + } + draw(); + }; + + finder.search.addEventListener("input", draw); + // 한 번 누름 = 고름만(두 번째 누름 · 키보드 = 연결) + finder.root.addEventListener( + "click", + (ev) => { + if ((ev.target as Element).closest("[data-pick]") && (ev as MouseEvent).detail === 1) + ev.stopPropagation(); + }, + true, + ); + finder.root.addEventListener("contextmenu", (ev) => { + const row = (ev.target as Element).closest("[data-pick]"); + const item = row ? shown[Number(row.dataset.pick)] : undefined; + if (!item) return; + ev.preventDefault(); + openMenuAt(ev.clientX, ev.clientY, [ + ["고른 내역 줄에 연결", () => linkTo(item)], + ...(item.sheet + ? [["계산서 보기", () => item.sheet?.(() => linkTo(item))] as [string, () => void]] + : []), + ]); + }); + + const body = el("div", { + className: "b09-store", + attrs: { "data-b09-store": "" }, + children: [tabs.root, finder.root, guide], + }); + const side = createSidePanels({ + prefKey: "b09-store", + panels: [{ id: "store", title: "재료 창고", body }], + defaultWidth: 360, + }); + + /** 내역 표 줄에 놓기 — 표를 다시 그리면 새 표에 다시 붙임 */ + const dropOn = (table: HTMLElement): void => { + let over: HTMLElement | null = null; + const mark = (tr: HTMLElement | null): void => { + over?.classList.remove("is-focus"); + over = tr; + over?.classList.add("is-focus"); + }; + table.addEventListener("dragover", (ev) => { + if (!ev.dataTransfer?.types.includes(DRAG)) return; + ev.preventDefault(); + mark((ev.target as Element).closest("tr[data-i]")); + }); + table.addEventListener("dragleave", (ev) => { + if (!table.contains(ev.relatedTarget as Node)) mark(null); + }); + table.addEventListener("drop", (ev) => { + const at = ev.dataTransfer?.getData(DRAG); + const tr = (ev.target as Element).closest("tr[data-i]"); + mark(null); + if (!at || !tr) return; + ev.preventDefault(); + const item = shown[Number(at)]; + if (item) linkTo(item, Number(tr.dataset.i)); + }); + }; + + side.root.classList.add("b09-store__side"); + return { + root: side.root, + bind: (next, rows, table) => { + ctx = next; + raw = rows; + dropOn(table); + draw(); + }, + }; +} + +/** 설계내역서 표 오른쪽 창고 — 표(root)에 놓기 붙이고 창고 서랍을 돌려줌 */ +export function attachBillStore(ctx: TabContext, raw: DataRow[], table: HTMLElement): HTMLElement { + store ??= makeStore(); + store.bind(ctx, raw, table); + return store.root; +} diff --git a/B09_Estimation/B09_Estimation_UI_Tabs_Bill.ts b/B09_Estimation/B09_Estimation_UI_Tabs_Bill.ts index e53db9eb4..2bca9c6f8 100644 --- a/B09_Estimation/B09_Estimation_UI_Tabs_Bill.ts +++ b/B09_Estimation/B09_Estimation_UI_Tabs_Bill.ts @@ -11,6 +11,7 @@ * 단가연결 칸(램프) = 항목 줄(자재 · 조달수수료 빼고) · 램프 누름 = 우클릭 [연결] 과 같은 메뉴 * 접히지 않는 나무(235-1) = 폴더(묶음 · 자식 있는 줄) = 이름만 · 수량 · 단가 빈칸 · 금액 = 자손 합 수식(읽기 전용) · * 파일(항목) = 이름 · 규격 · 단위 · 수량 + 연결 · 안내선 · 아이콘 = 공용 표 level.tree · 고칠 칸 = 더블클릭 입력 + * 오른쪽 재료 창고(703-1) = `…_UI_Store`(두 번 누름 · 끌어 놓기 = 단가연결) * ========================================================================== */ import type { DataRow } from "@ui/ui_template_data_table"; @@ -25,6 +26,7 @@ import { type BillTable, } from "./B09_Estimation_UI_Tabs_Bill_Edit"; import { attachBillFold } from "./B09_Estimation_UI_Tabs_Bill_Fold"; +import { attachBillStore } from "./B09_Estimation_UI_Store"; const TEXT_KEYS = ["name", "spec", "unit"]; /** 폴더 줄 수식 칸 — 자손 합(셈) */ @@ -128,6 +130,7 @@ export const buildBill: TabBuild = (ctx): BillTable => { menu: (i) => billMenu(ctx, raw, i), drop: (i, parent, before) => dropMove(ctx, raw, i, parent, before), fold: (table) => attachBillFold(ctx, raw, table), // 702-1 줄 펼침 · 고친 칸 덮개 + side: (table) => attachBillStore(ctx, raw, table), // 703-1 오른쪽 재료 창고 onCell: (i, key) => { if (key === "connect") openLinkMenu(ctx, raw, i); }, diff --git a/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Edit.ts b/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Edit.ts index ca6bf6e32..1f102dad6 100644 --- a/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Edit.ts +++ b/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Edit.ts @@ -34,6 +34,8 @@ export type BillTable = TabTable & { drop?: (index: number, parent: string | null, before: string | null) => (() => void) | null; /** 줄 펼침(702-1) — 표 root 를 받아 표 아래 자리를 돌려줌 */ fold?: (table: HTMLElement) => HTMLElement; + /** 재료 창고(703-1) — 표 root 를 받아(놓기) 오른쪽 서랍을 돌려줌 */ + side?: (table: HTMLElement) => HTMLElement; }; const NEW_NAME = "새 줄"; @@ -222,6 +224,10 @@ function applyRef(ctx: TabContext, rows: DataRow[], i: number): ApplyRef { }; } +/** 재료 창고(703-1) — 그 줄에 연결 적용 · 연결 없는 줄(자재 · 묶음 · 조달수수료) = null */ +export const applyAt = (ctx: TabContext, rows: DataRow[], i: number): ApplyRef | null => + linkable(rows[i]) ? applyRef(ctx, rows, i) : null; + /** 줄 연결 메뉴 — 지금 연결 = 덮개(로직 입력값 등) 있으면 덮개 · 없으면 셈 줄 */ function linkFor(ctx: TabContext, rows: DataRow[], i: number) { const row = rows[i]; diff --git a/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Level.ts b/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Level.ts index f0b333bd9..656772592 100644 --- a/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Level.ts +++ b/B09_Estimation/B09_Estimation_UI_Tabs_Bill_Level.ts @@ -45,6 +45,9 @@ let live: { } | null = null; let keysOn = false; +/** 고른 줄 키(703-1 재료 창고 두 번 누름 = 이 줄에 연결) */ +export const pickedKey = (): string | null => picked; + /** 고른 줄 class — Shell 줄 class 곁값 */ export const pickedClass = (row: DataRow | undefined): string | null => row && picked !== null && String(row.key) === picked ? "is-focus" : null; diff --git a/resources/tester/test_200_2_b09_bill_level_bar.py b/resources/tester/test_200_2_b09_bill_level_bar.py index c3ccb5dd5..23e35fbb5 100644 --- a/resources/tester/test_200_2_b09_bill_level_bar.py +++ b/resources/tester/test_200_2_b09_bill_level_bar.py @@ -202,9 +202,9 @@ def test_셸_배선(): ) # 239-1 · 242-1 이동 줄 빨강 곁(고름과 한때 하나) assert "if (level) bars.setTools(level.tools);" in src # 229-1 단추 = 보조 탭 줄 assert ( - "panel.replaceChildren(...banner, table.root, ...(fold ? [fold] : []), ...(foot ? [foot] : []))" - in src - ) # 203 레벨 안내 + 탭 안내 = 한 영역 + "const body = [table.root, ...(fold ? [fold] : []), ...(foot ? [foot] : [])];" in src + and "panel.replaceChildren(...banner, ...(row ? [row] : body));" in src + ) # 203 레벨 안내 + 탭 안내 = 한 영역 · 703-1 창고 있으면 표 칸 + 오른쪽 서랍 lvl = (B09 / "B09_Estimation_UI_Tabs_Bill_Level.ts").read_text("utf-8") assert "table.menu(index)" in lvl # 단추 · 키 = 우클릭 메뉴 같은 함수 assert "b09-estimation__level" not in lvl diff --git a/resources/tester/test_202_1_table_hint_bottom.py b/resources/tester/test_202_1_table_hint_bottom.py index a953cf527..5d89460f6 100644 --- a/resources/tester/test_202_1_table_hint_bottom.py +++ b/resources/tester/test_202_1_table_hint_bottom.py @@ -106,7 +106,9 @@ def test_묶음_탭_단추가_보조_줄에_안내는_아래에(): def test_잇기_쉘_안내_줄_아래_도구_비움(): shell = (ROOT / "B09_Estimation" / "B09_Estimation_UI_Shell.ts").read_text("utf-8") assert ( - "panel.replaceChildren(...banner, table.root, ...(foot ? [foot] : []))" in shell # 701-3 띠 = 표 위 + "const body = [table.root, ...(fold ? [fold] : []), ...(foot ? [foot] : [])];" in shell + and "panel.replaceChildren(...banner, ...(row ? [row] : body));" + in shell # 701-3 띠 = 표 위 ) # 229-1 레벨 단추 = 보조 탭 줄 · 안내 글 = 표 아래 · 203 레벨 안내 + 탭 안내 = 한 영역(맨 아래) assert "...(hint ? [hint] : []), table.root" not in shell # 위 자리 없음 assert re.search(r"bars\.draw\(tab\);\s*bars\.setTools\(\[\]\);", shell) diff --git a/resources/tester/test_703_1_b09_past.py b/resources/tester/test_703_1_b09_past.py new file mode 100644 index 000000000..36ea3bbfc --- /dev/null +++ b/resources/tester/test_703_1_b09_past.py @@ -0,0 +1,147 @@ +"""703-1 B09 재료 창고 「지난 공사」 — 같은 회사 다른 공사 일위대가 → 이 공사 서고 사본(덮개째). + +- 목록 = 그 공사 서고 사본 · 구조물 사본 · 고친 칸 수(그 공사 저장 덮개) · 같은 것 한 줄 +- 가져옴 = 사본 폴더 통째 → `library/…~해시` · 가져온곳 · 덮개 = 그 공사 칸 · 다시 = 같은 사본 +- 새 호표(`libs`) · 같은 꼴 블록이 이 공사에 먼저 있으면 그 블록 cover +- 모양 틀림 400 · 없음 404 · 다른 회사 403 · 이 공사 400 +임시 층(견본 마스터 · 임시 storage) · 실제 마스터 · 프로젝트는 안 씀. +""" + +import asyncio +import json +import sys +from pathlib import Path + +import pytest +from fastapi import HTTPException + +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_Bill_Library as library # noqa: E402 +from B09_Estimation import B09_Estimation_Past as past # noqa: E402 +from B09_Estimation import B09_Estimation_Router as router # noqa: E402 +from B09_Estimation import B09_Estimation_Store as store_b09 # noqa: E402 +from B09_Estimation.B09_Estimation_Labor_Source import daega_inputs # noqa: E402 +from config import config_system # noqa: E402 +from M02_MasterTemplete import M02_Labor_Ref as refs # noqa: E402 +from M02_MasterTemplete import M02_MasterTemplete_Store as store # noqa: E402 +from M02_MasterTemplete import M02_Template_Layers as layers # noqa: E402 +from resources.tester.helper_m02_master_sample import copy_master_sample # noqa: E402 + +STONE = "GF000219" # 돌쌓기 메쌓기 원/㎡ + + +@pytest.fixture() +def world(tmp_path, monkeypatch): + system = copy_master_sample(tmp_path / "master") + monkeypatch.setattr(store, "FOLDER", system) + monkeypatch.setattr(layers, "SYSTEM_ROOT", system) + monkeypatch.setattr(config_system, "STORAGE_BASE_DIR", str(tmp_path / "storage")) + with store.at(system): + key = refs.create( + "precombo", + {"이름": "지난 조합", "단위": "㎡", "담은로직": [{"로직": STONE, "수량": {"손": 2}}]}, + )["이름"] + a, b = (tmp_path / "storage" / "7" / "1" / n for n in ("past", "here")) + a.mkdir(parents=True) + b.mkdir(parents=True) + folder = library.import_copy(a, "precombo", "system", None, key)["폴더"] + ref = {"층": "system", "주인": None, "키": key} + cover = { + f"C:{refs.ref_id(ref)}": {"sangeun:GF#0": {"qty": 5}}, + "K:x": {"@copy": {"from": "S:y"}}, + } + store_b09.write_user(a, {"daega_cover": cover}) + return {"key": key, "a": a, "b": b, "folder": folder} + + +def test_목록_서고_사본_고친_칸_수_같은_것_한_줄(world): + a = world["a"] + rows = past.rows_of(a) + assert [(r["cover"], r["name"], r["unit"], r["kind"], r["covers"]) for r in rows] == [ + (f"L:{world['folder']}", "지난 조합", "㎡", "사전조합", 1) + ] + # 같은 원본 · 같은 값 · 덮개 없음 = 한 줄로 셈(값 해시 다른 사본) + library.import_copy(a, "precombo", "system", None, world["key"], haul={"given": {}}) + assert len(past.rows_of(a)) == 1 + + +def test_가져옴_사본_통째_덮개째_새_호표_다시는_같은_사본(world): + a, b, folder = world["a"], world["b"], world["folder"] + ref = {"project_id": "P-A", "프로젝트": "지난"} + made = past.import_past(b, a, ref, f"L:{folder}", {"이름": "나"}) + name = made["폴더"] + assert made["만듦"] and made["덮개"] == {"sangeun:GF#0": {"qty": 5}} + assert name.startswith(f"precombo@system@-@{world['key']}~") and library.NAME.match(name) + copy = library.library_dir(b) / name + src = library.library_dir(a) / folder + for f in ("일위대가.json", "단가.json"): + assert (copy / f).read_bytes() == (src / f).read_bytes() + manifest = json.loads((copy / "manifest.json").read_text("utf-8")) + assert manifest["가져온곳"] == {**ref, "사본": f"L:{folder}"} and manifest["종류"] == "precombo" + got = daega_inputs(b) + bid = got["libs"][name] + block = next(x for x in got["blocks"] if x["id"] == bid) + # 사전조합 덮개 = 참조(공사 안 같은 사전조합 한 덮개) — 덮개자리 = 그 cover + assert (block["name"], block["cover"]) == ("지난 조합", made["덮개자리"]) + assert made["덮개자리"] == "C:참조|system||" + world["key"] + again = past.import_past(b, a, ref, f"L:{folder}") + assert (again["폴더"], again["만듦"]) == (name, False) + + +def test_같은_꼴_블록이_먼저_있으면_그_cover(world): + a, b = world["a"], world["b"] + mine = library.import_copy(b, "precombo", "system", None, world["key"])["폴더"] + name = past.import_past(b, a, {"project_id": "P-A"}, f"L:{world['folder']}")["폴더"] + got = daega_inputs(b) + assert got["libs"][name] == got["libs"][mine] + block = next(x for x in got["blocks"] if x["id"] == got["libs"][name]) + assert block["cover"].startswith("C:") # 사전조합 = 같은 참조 한 덮개(화면이 빈 때만 얹음) + + +def test_구조물조합_사본_덮개자리_새_폴더(world): + a, b = world["a"], world["b"] + folder = library.import_copy(a, "combo", "system", None, "SS000011")["폴더"] + store_b09.write_user(a, {"daega_cover": {f"L:{folder}": {"x#0": {"qty": 2}}}}) + row = next(r for r in past.rows_of(a) if r["cover"] == f"L:{folder}") + assert (row["kind"], row["covers"]) == ("구조물 조합", 1) + made = past.import_past(b, a, {"project_id": "P-A"}, f"L:{folder}") + assert made["덮개자리"] == f"L:{made['폴더']}" and made["덮개"] == {"x#0": {"qty": 2}} + got = daega_inputs(b) + block = next(x for x in got["blocks"] if x["id"] == got["libs"][made["폴더"]]) + assert block["cover"] == made["덮개자리"] + + +def test_모양_틀림_없음(world): + a, b = world["a"], world["b"] + for bad in ("L:../x", "X:y", "S:../../z"): + with pytest.raises(ValueError): + past.import_past(b, a, {}, bad) + with pytest.raises(LookupError): + past.import_past(b, a, {}, "S:nope") + with pytest.raises(LookupError): + past.import_past(b, a, {}, "L:precombo@system@-@SC-000999") + + +def test_길_다른_회사_403_이_공사_400(world, monkeypatch): + rows = { + "here": {"company_id": 7, "root": world["b"]}, + "far": {"company_id": 8, "root": world["a"]}, + } + + async def project(_session, pid): + return {"name": pid, **rows["here" if pid.startswith("0") else "far"]} + + monkeypatch.setattr(router, "_project", project) + pid = router.UUID("00000000-0000-0000-0000-000000000001") + body = router.PastBody(project_id="far", cover=f"L:{world['folder']}") + with pytest.raises(HTTPException) as e: + asyncio.run(router.past_import(pid, body, {"user_id": 1})) + assert e.value.status_code == 403 + same = router.PastBody(project_id=str(pid), cover="L:x") + with pytest.raises(HTTPException) as e: + asyncio.run(router.past_import(pid, same, {"user_id": 1})) + assert e.value.status_code == 400 + assert not library.library_dir(world["b"]).exists() # 아무것도 안 씀