refactor(855-2-C1): 단가산출 셈 한 길 — 줄 · 비목 · 끝수 · 기준 모두 수식 사본 문서 셈 · 옛 엔진(run_line) 안 돎
- `Sangeun_Calc.run` = 수식 사본 문서 셈 답으로 답 꼴 채움(기준 · 1단위 · 배 · 줄 cid 「금액#n」 · 단위 · 끝수 · 까닭 · 수식셈 · 바탕판 · 꼬리표) · 빠진줄 · 짝잃음 = 빈 목록(옛 칸 개념) - 수식 사본 없는 SK(바탕 참조) · 옛 칸 고침 파생 SK(덮개 · 뺀줄 · 더한줄 · 수식고침 · 식 칸) = 못 셈 + 까닭 하나(올림 없음) · `sub_run`(둘째 기초) 도 못 셈 - 굳힌 사본 SK(B09 · 구조물 사본 GX9 · 수식 없음) = 옛 길 그대로(`_frozen` · B9 걸음 몫) - `Doc_Sk.derive` = 옛 엔진 ctx 없이 기초 문서 사본 + 줄 규칙(입력값 · 켜쌓기율 · 고름 · 자재표시) · `copy_of(sk, whole)` · `on_run` 걷음 · 저장 `settle` = 옛 셈 안 돎 · 저장 관문 읽은 줄 = 문서 셈 + 부름 줄(826-3) · 저장 전 새 SK = 지금 M01 값 · 열린 목록 · 내 기계 고른 값 = 목록에 더함 - `Doc_Sk_Path.current` · `Labor_Copy.line`(사본 있으면 문서만) · `Doc_Import._old_ctx` 걷음(엔진 더한줄 = 못 셈) · `Sangeun_Const.answer` 보기 덧칸 없음 - 층 서고 SK 14 전후: 기준 · 1단위 · 배 · 까닭 · 바탕판 다름 0 · 줄 합 = 기준 11/14 → 14/14 · 「따로」 줄 0 → 4 · 한 번 셈 run_line 14 → 0(저장 25 → 0) - 시험: test_855_sk_layers 「따로」 단언 뒤집음(줄 합 = 기준 · 줄 > 0 · 옛 엔진 부름 0 · 옛 칸 = 못 셈) · golden_855_b09 다시 뜸(daega_inputs — 「율 더한줄」 SK = 옛 칸 = 못 셈 → 그 블록 m02 없음 · 그 밖 같음) - 지운 시험(옛 칸 셈만 붙듦 — 덮개 · 뺀줄 · 더한줄 · 율 더한줄 · 수식고침 · 식 칸 · 상수 · 표값 덮개 · 넣은 SK 몸 · 줄 패치 · 보기 글 · 옵션꺼짐 줄): 715_sangeun_engine · 717_2b · 725_1 · 744_1 · 750_1 파일 · 715_3 셋 · 715_store 다섯 · 727 넷 · 728_2 하나 · 740_1 일곱 · 742_1 하나 · 753_1 하나 · 778_4 여섯 · 790_2 다섯 · 792_1 일곱 · 792_2 하나 · 795_1 하나 · 795_2 하나 · 796_2b 셋 · 822_1 하나 · logic_mats 둘(일위대가 옛 로직 줄 재료 목록 — 사본 셈 = 문서) - 고친 시험(살아 있는 결과): 728_2 금액 = 수식 문서 기본 옵션 · 747_1 줄 이름 · 별도계상 합밖 · 721 일위대가 쪽만 · 793_2 옛 시트 같음 단언 둘 뺌 · 795_1 노임 키 = 값 사본 · 802_4a · 802_4b2 부름 = 기초 문서가 부르는 단가산출(GC000006) · 811_1 모달 저장 = 수식 길 · 821_1 · 822_2 · 778_2 = 바탕 로직 + 입력값 · 826_3 저장 셈 1 → 0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,7 +72,7 @@ def _index(sk: dict, master: Any = None, doc: Any = None) -> Any:
|
||||
|
||||
# ── 엑셀 단가 그대로 고친 줄(가져온 로직 줄 + SK 고침 · 엔진 셈 없음) ─────────
|
||||
def _engine_adds(doc: dict) -> bool:
|
||||
"""값을 엔진 셈으로만 얻는 더한줄(형제 SK · 율 · 세부 고친 둘째 기초)이 있음 — 옛 길(`_old_ctx`)."""
|
||||
"""값을 엔진 셈으로만 얻는 더한줄(형제 SK · 율 · 세부 고친 둘째 기초)이 있음 — 못 셈(옛 셈 은퇴)."""
|
||||
return any(
|
||||
one.get("참조") or sd.is_rate(one) or sd.sub_patched(one) for one in doc.get("더한줄") or []
|
||||
)
|
||||
@@ -82,7 +82,7 @@ def _ctx(sk: dict, whole: Any) -> tuple:
|
||||
"""엑셀 단가 기준 고친 줄(855 2-C2) — 가져온 로직 줄(`row_of`) + 수식 고침 · SK 고침(`sd.patched`) ·
|
||||
더한줄 고정 값(`fixed.line`) → (색인, 키, 입력, {정체}, None) · 옛 엔진 안 돎.
|
||||
안쪽 산근(형제 SK) 줄 값 = 0 자리값(`_attach` 가 형제 SK 연결 + 엑셀 값으로 갈음).
|
||||
`_engine_adds` 인 SK 만 옛 셈 길(그 더한줄 값이 엔진 답 — 2-C1 · 2-C5 몫)."""
|
||||
`_engine_adds` 인 SK = 못 셈(그 더한줄 값이 옛 엔진 답 — 옛 셈 은퇴 · 855 2-C1)."""
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from M02_MasterTemplete import M02_Sangeun_Copy as skc
|
||||
from M02_MasterTemplete import M02_Sangeun_Equation as eqm
|
||||
@@ -90,7 +90,7 @@ def _ctx(sk: dict, whole: Any) -> tuple:
|
||||
raw = {**sk, imp.KEY: {**sk[imp.KEY], "단가기준": "엑셀"}}
|
||||
doc = sd.clean(raw, None, whole)
|
||||
if _engine_adds(doc):
|
||||
return _old_ctx(raw, whole)
|
||||
raise ValueError("형제 SK · 율 · 고친 둘째 기초 더한줄 — 옛 엔진 셈 은퇴 · 못 셈")
|
||||
w = skc.over(doc, whole)
|
||||
base = sd.empty_row(doc)
|
||||
base = {**base, "호표": [dict(x) for x in base.get("호표") or []]}
|
||||
@@ -113,20 +113,6 @@ def _ctx(sk: dict, whole: Any) -> tuple:
|
||||
return _Row(w, key, {**row, "키": key}), key, values, {"정체": got["정체"]}, None
|
||||
|
||||
|
||||
def _old_ctx(raw: dict, whole: Any) -> tuple:
|
||||
"""옛 셈 길(`OLD`)로 돌려 엔진에 넣은 (색인, 키, 입력, 답, 재료) — `_engine_adds` SK 만."""
|
||||
from M02_MasterTemplete import M02_Doc_Sk as dsk
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
|
||||
box: list = []
|
||||
token = dsk.OLD.set(True)
|
||||
try:
|
||||
calc.run(sd.clean(raw, None, whole), whole, catch=box)
|
||||
finally:
|
||||
dsk.OLD.reset(token)
|
||||
return box[-1]
|
||||
|
||||
|
||||
# ── 소요량 · 계수 고른 칸 → 수 자리에 기호 ──────────────────────────────
|
||||
def _swap_nth(node: Any, n: int, new: tuple, seen: list) -> Any:
|
||||
"""`M02_Sangeun_QtyLinks._literals` 차례의 n 번째 수 → `new` 마디(같은 걸음 규칙)."""
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
SK `수식`(꼴 = `M02_Doc_Copy`) — `문서` = 이 SK 문서(키 = SK 키 · 옵션 값 · 줄 규칙까지 든 정본) ·
|
||||
`부름` = 부르는 단가산출 닫힌 묶음 · `끊음` = 이 사본에 굳힌 부름(고칠 수 있음) · 값 사본.
|
||||
두 갈래:
|
||||
파생(따로 없음) — 옛 칸(바탕 · 덮개 · 뺀줄 · 더한줄 · 수식고침 …)이 정함: 셈마다 옛 칸이 낸 줄
|
||||
(`M02_Sangeun_Calc.run` 이 엔진에 넣는 고친 줄)을 문서로 옮겨(덮개 없는 바탕 = M01 문서 사본 ·
|
||||
고친 줄 = `master_doc_convert`) 문서 셈 · 지금 화면(옛 칸 고침)이 그대로 돎.
|
||||
파생(따로 없음) — 셈마다 바탕 로직의 기초 문서 사본 + 줄 규칙(입력값 · 켜쌓기율 · 고름 · 자재표시)으로
|
||||
다시 지음(`derive` · 옛 엔진 안 돎 · 855 2-C1) · 옛 칸 고침(덮개 · 뺀줄 · 더한줄 · 수식고침 …) =
|
||||
못 셈(올림 없음).
|
||||
따로 — 수식 길(`M02_Doc_Router`)로 문서를 고침: 저장한 문서가 정본 · 옛 칸 고침 저장 = 409 ·
|
||||
[재생성] = 지금 M01 로 다시 찍어 파생으로 돌아감(고친 문서 버림).
|
||||
SK 금액(기준 · 1 단위 = 기준 ÷ 배) = 문서 셈 — 일위대가 · 사전조합 · 구조물 조합이 이 값을 씀.
|
||||
@@ -24,7 +24,6 @@ from __future__ import annotations
|
||||
import copy as cp
|
||||
import json
|
||||
from contextvars import ContextVar
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
|
||||
from M02_MasterTemplete import M02_Doc_Copy as dc
|
||||
@@ -83,6 +82,10 @@ def _set_values(doc: dict, given: dict) -> None:
|
||||
link = var.get("연결") or {}
|
||||
if link.get("갈래") in ("선택", "입력") and var.get("열쇠") in given:
|
||||
link["값"] = given[var["열쇠"]]
|
||||
have = list(link.get("목록") or [])
|
||||
mine = str(link["값"]).startswith("개인 ") # 내 기계 원문번호(821-1)
|
||||
if link["갈래"] == "선택" and link["값"] not in have and (mine or not have):
|
||||
link["목록"] = [*have, link["값"]] # 열린 목록 · 내 기계 = 고른 값을 목록에
|
||||
|
||||
|
||||
def base_doc(sk: dict, whole: Any, key: str) -> tuple[dict | None, bool]:
|
||||
@@ -115,35 +118,58 @@ def _bare_doc(doc: dict) -> dict:
|
||||
return {k: v for k, v in doc.items() if k not in (mcv.COVER, mcv.HAND)}
|
||||
|
||||
|
||||
def derive(sk: dict, ctx: tuple) -> dict:
|
||||
"""옛 칸이 낸 고친 줄(`ctx` = run 이 엔진에 넣은 (색인, 키, 입력, 바탕 답)) → 이 SK 문서.
|
||||
덮개 없는 바탕(고친 줄 = 바탕 줄) = 기초 문서(`base_doc`) 사본 · 아니면 고친 줄 변환 ·
|
||||
옵션 = 기초 문서 기본 위에 내가 고른 값(848-10 · 옛 로직 줄 자동값이 기초 고침을 안 이김)."""
|
||||
whole, key, values, got, mats = ctx
|
||||
row = whole.logic(key)
|
||||
given = dc.given_of(whole, key, values)
|
||||
mine = {k: v for k, v in given.items() if k in (values or {})} # 내가 고른 값
|
||||
OLD_PATCH = (*_PATCH, "변수줄", "식덮개") # 옛 칸 고침(덮개 · 더한줄 · 식 칸 …) — 셈 은퇴(855 2-C1)
|
||||
OLD_WHY = "옛 칸(덮개 · 뺀줄 · 더한줄 · 수식고침 …)으로 고친 단가산출 — 옛 칸 셈 은퇴 · 수식 문서로 다시 만들어야 셈"
|
||||
REF_WHY = "바탕 참조 단가산출 — 수식 문서 없음 · 못 셈"
|
||||
|
||||
|
||||
def frozen(sk: dict) -> bool:
|
||||
"""굳힌 사본 SK(B09 · 구조물 사본 `GX9…` 굳힌 줄 · 수식 사본 없음) — 바탕 로직에 M01 수식 문서
|
||||
없음 · 셈 = 옛 길(B9 걸음 몫 · 855 2-C1 은 안 건드림)."""
|
||||
key = str((sk.get("바탕") or {}).get("로직") or "")
|
||||
return bool(key) and not dc.has(sk) and key not in dc.folder()
|
||||
|
||||
|
||||
def old_only(sk: dict) -> bool:
|
||||
"""옛 칸 고침이 든 파생 SK(가져온 식 빼고 — 그 문서는 `M02_Doc_Import` 가 지음) — 셈 안 함."""
|
||||
return not dim.is_imported(sk) and any(sk.get(k) not in (None, {}, []) for k in OLD_PATCH)
|
||||
|
||||
|
||||
def derive(sk: dict, whole: Any) -> dict:
|
||||
"""이 SK 문서(855 2-C1 · 옛 엔진 안 돎) — 바탕 로직 = 기초 문서(`base_doc`) 사본 · 바탕 없음 = 빈 문서 ·
|
||||
옵션 = 기초 문서 기본 위에 내가 고른 값(848-10 · 손고침 · 프로젝트 층 = 옛 로직 줄 자동값) ·
|
||||
줄 규칙(켜쌓기율 · 고름 · 자재표시 · 일위대가 [+ 줄] 사본 811-1) = 문서 규칙(`dc.line_doc` ·
|
||||
SK 재료 빈 칸 = 직접계산 747-1). `whole` = 값 사본 색인. 옛 칸 고침 SK 는 부르는 쪽이 먼저 막음."""
|
||||
key = str(sk.get("키") or "")
|
||||
base_key = str((sk.get("바탕") or {}).get("로직") or "")
|
||||
plain, real = None, False
|
||||
if base_key:
|
||||
try:
|
||||
frozen = whole.logic(base_key)
|
||||
same = {**row, "키": base_key} == frozen
|
||||
except dc._ERR:
|
||||
same = False
|
||||
plain, real = base_doc(sk, whole, base_key) if same else (None, False)
|
||||
if plain is not None:
|
||||
doc = cp.deepcopy(_bare_doc(plain)) # ① = `위덮음`(848-1)
|
||||
_set_values(doc, mine if real else given)
|
||||
elif not (row.get("호표") or row.get("덧줄") or row.get("결과")):
|
||||
doc = dc.md.blank(str(sk.get("키") or ""), str(sk.get("이름") or ""))
|
||||
else:
|
||||
live = dc.folder().get(base_key) if base_key and renew.on() else None
|
||||
given = {**given, **renew._opts(live), **mine} if live else given
|
||||
doc = dc.cv.convert(whole, row, given)[0]
|
||||
apart = dc.apart_of(got.get("자재표시"), mats)
|
||||
doc = dc.line_doc(doc, got.get("켜쌓기율"), got.get("고름") or None, apart)
|
||||
return {**doc, "키": str(sk.get("키") or key), "이름": str(sk.get("이름") or doc.get("이름"))}
|
||||
if not base_key:
|
||||
return {**dc.md.blank(key, str(sk.get("이름") or "")), "키": key}
|
||||
plain, real = base_doc(sk, whole, base_key)
|
||||
if plain is None:
|
||||
raise ValueError(f"기초 문서 없음 「{base_key}」")
|
||||
row = whole.logic(base_key)
|
||||
got = sd.patched(row, sk) # 줄 규칙 칸 cid → 차례(옛 칸 고침 없음 = 바탕 줄 그대로)
|
||||
names = {str(i.get("이름")) for i in row.get("입력") or []}
|
||||
values = {k: v for k, v in (sk.get("입력값") or {}).items() if k in names}
|
||||
given = dc.given_of(whole, base_key, values) if values or not real else {}
|
||||
doc = cp.deepcopy(_bare_doc(plain)) # ① = `위덮음`(848-1)
|
||||
_set_values(doc, {k: v for k, v in given.items() if k in values} if real else given)
|
||||
apart = [] if isinstance(row.get("흐름"), dict) else _apart(got)
|
||||
doc = dc.line_doc(doc, sk.get("켜쌓기율"), got["고름"] or None, apart)
|
||||
return {**doc, "키": key or base_key, "이름": str(sk.get("이름") or doc.get("이름"))}
|
||||
|
||||
|
||||
def _apart(got: dict) -> list[int]:
|
||||
"""별도계상 재료 줄 차례 — SK 빈 칸 = 직접계산(747-1) · 「별도계상」 고른 줄만."""
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor # 늦게 — 일위대가 셈이 이 파일을 부름
|
||||
|
||||
marks = got["자재표시"]
|
||||
return [
|
||||
n
|
||||
for n, item in enumerate(got["줄"].get("호표") or [])
|
||||
if item.get("종류") == "재료"
|
||||
and labor.apart({"별도계상": "직접계산", **labor.marks(marks.get(str(n)))})
|
||||
]
|
||||
|
||||
|
||||
def seed(sk: dict) -> dict | None:
|
||||
@@ -188,26 +214,30 @@ def upper(sk: dict, got: Any) -> Any:
|
||||
return with_upper(sk, got)
|
||||
|
||||
|
||||
def copy_of(sk: dict, ctx: tuple | None) -> dict | None:
|
||||
"""셈에 쓸 수식 사본 — 따로 = 저장본 · 파생 = 지금 옛 칸으로 다시 지은 문서(부름은 있던 것 먼저) ·
|
||||
`OLD` 켬(옮기기 대조 · 시험) = 옛 길."""
|
||||
if OLD.get() or not own(sk):
|
||||
def copy_of(sk: dict, whole: Any = None) -> dict | None:
|
||||
"""셈에 쓸 수식 사본 — 따로 = 저장본 · 파생 = 지금 다시 지은 문서(부름은 있던 것 먼저 · 옛 엔진 안 돎) ·
|
||||
사본 없음(바탕 참조) · 옛 칸 고침 파생 SK = None(못 셈 · 855 2-C1). `whole` = 셈 색인(없으면 SK 값 사본)."""
|
||||
if not own(sk):
|
||||
return None
|
||||
got = sk.get(KEY) if dc.has(sk) else seed(sk)
|
||||
if got is None and "로직" in (sk.get("바탕") or {}) and not frozen(sk):
|
||||
got = {"부름": {}} # 저장 전 새 SK = 지금 M01 값(값 사본은 [저장] 때 찍음)
|
||||
if got is None:
|
||||
return None
|
||||
got = upper(sk, renew.form(sk, got)) # M01 자동 따라옴(836-2) · ① 위 층 덮음(848-1)
|
||||
if got.get("따로") or ctx is None:
|
||||
if got.get("따로"):
|
||||
return carry.carry(sk, got) # 848-7 가져온 식 ① = 가져온 값
|
||||
if dim.is_imported(sk): # 가져온 식 — 엑셀 단가 기준 줄에서 지음(우리 = 한 번 더 돎)
|
||||
if old_only(sk):
|
||||
return None
|
||||
whole = whole if whole is not None else skc.over(sk, skc.whole_())
|
||||
if dim.is_imported(sk): # 가져온 식 — 엑셀 단가 기준 줄에서 지음(`Doc_Import._ctx`)
|
||||
try:
|
||||
same = dim.basis_of(sk) == "엑셀"
|
||||
root = dim.derive(sk, ctx if same else None, dc.base(ctx[0]))
|
||||
root = dim.derive(sk, None, dc.base(whole))
|
||||
except dc._ERR as e:
|
||||
root = {**dc.md.blank(str(sk.get("키"))), "_틀림": str(e)}
|
||||
return carry.carry(sk, {**got, "문서": root, "부름": {}})
|
||||
try:
|
||||
root = renew.carry(got, derive(sk, ctx)) # 맡긴 기계 덮음(836-2)
|
||||
root = renew.carry(got, derive(sk, whole)) # 맡긴 기계 덮음(836-2)
|
||||
except dc._ERR as e:
|
||||
root = {**dc.md.blank(str(sk.get("키"))), "_틀림": str(e)}
|
||||
values = dc.values_of(sk[skc.KEY]) if skc.has(sk) else dc.values_of(got) # 서버가 정한 값
|
||||
@@ -220,22 +250,6 @@ def copy_of(sk: dict, ctx: tuple | None) -> dict | None:
|
||||
return {**got, **values, "문서": root, "부름": calls, **origin}
|
||||
|
||||
|
||||
def on_run(sk: dict, ans: dict, ctx: tuple | None) -> dict:
|
||||
"""`M02_Sangeun_Calc.run` 끝 — 수식 사본 있는 SK 금액 = 문서 셈(기준 · 1 단위) + 덧칸 `수식셈`."""
|
||||
copy = copy_of(sk, ctx)
|
||||
if copy is None:
|
||||
return ans
|
||||
got = run(sk, copy, ctx[0] if ctx else None)
|
||||
money = dc.money(got)
|
||||
base = {k: Decimal(str(v)) for k, v in money.items()} if money else None
|
||||
times = Decimal(str(ans.get("배") or 1))
|
||||
unit = {k: v / times for k, v in base.items()} if base else None
|
||||
mark = {"셈됨": bool(base), "따로": bool(copy.get("따로"))}
|
||||
if not base:
|
||||
mark["까닭"] = copy["문서"].get("_틀림") or dc.why(got) or "돈 아닌 문서"
|
||||
return {**ans, "기준": base, "1단위": unit, "수식셈": mark}
|
||||
|
||||
|
||||
def run(sk: dict, copy: dict, master: Any = None) -> dict:
|
||||
"""문서 셈 — 가져온 식 = 단가기준 · 형제 SK(`dim.run`) · 그 밖 = 값 사본(`dc.run`)."""
|
||||
if dim.is_imported(sk):
|
||||
@@ -256,9 +270,8 @@ def norm(copy: dict) -> dict:
|
||||
|
||||
def settle(out: dict, whole: Any, job: Any, raw: Any) -> dict:
|
||||
"""저장 꼴에 `수식` 을 정함 — 수식 길 저장(`NEW`) = 그 사본 · 따로 = 저장본(옛 칸 고침 409 ·
|
||||
단가갱신 = 값만 · 재생성 = 파생으로) · 그 밖 = 옛 칸으로 다시 지음(부름 = 있던 것 · 재생성 = 새로)."""
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
|
||||
단가갱신 = 값만 · 재생성 = 파생으로) · 그 밖 = 다시 지음(부름 = 있던 것 · 재생성 = 새로 · 옛 엔진 안 돎) ·
|
||||
옛 칸 고침 파생 SK = 문서 없이 값 사본 · 부름만(못 셈)."""
|
||||
out = {k: v for k, v in out.items() if k != KEY}
|
||||
if not own(out):
|
||||
return out
|
||||
@@ -290,8 +303,6 @@ def settle(out: dict, whole: Any, job: Any, raw: Any) -> dict:
|
||||
if not skc.has(out) and not dim.is_imported(out):
|
||||
empty = seed(out)
|
||||
return {**out, KEY: norm(empty)} if empty else out
|
||||
box: list = []
|
||||
calc.run(out, whole, catch=box)
|
||||
calls = {} if job == skc.REGEN else (have or {}).get("부름") or {}
|
||||
first = {**(dc.values_of(out[skc.KEY]) if skc.has(out) else {}), "부름": calls}
|
||||
if job != skc.REGEN and (have or {}).get("끊음"): # 안 바뀐 항목 고침 = 그대로(836-2)
|
||||
@@ -302,7 +313,17 @@ def settle(out: dict, whole: Any, job: Any, raw: Any) -> dict:
|
||||
UPPER
|
||||
): # ① = 저장본(프로젝트 층) · 밖은 `copy_of` 가 지금 기초 것으로(848-1)
|
||||
first[UPPER] = have[UPPER]
|
||||
copy = copy_of({**out, KEY: first}, box[-1] if box else None)
|
||||
copy = copy_of({**out, KEY: first}, whole)
|
||||
if (
|
||||
copy and skc.READS.get() is not None
|
||||
): # 저장 관문 — 문서 셈 · 부름 줄이 읽은 줄을 적음(826-3)
|
||||
run({**out, KEY: copy}, copy, whole)
|
||||
index = dc.over(copy)
|
||||
for key in copy.get("부름") or {}: # 부름 문서를 가른 값 사본 줄(`dc.doc_of`)도 둠
|
||||
try:
|
||||
index.logic(key)
|
||||
except dc._ERR:
|
||||
pass
|
||||
if (
|
||||
copy and skc.has(out) and skc.READS.get() is None and (keys := gap.gaps(copy))
|
||||
): # 파생 — 옛 로직 사본에 박음(822-1)
|
||||
|
||||
@@ -60,24 +60,20 @@ def _settled(doc: dict, job: Any = None) -> tuple[dict, Any]:
|
||||
|
||||
|
||||
def current(doc: dict, job: Any = None) -> dict:
|
||||
"""그 SK 의 지금 수식 사본(할일 적용 · 저장 없음) — 따로 = 저장한 문서 · 파생 = 옛 칸으로 지음."""
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
|
||||
"""그 SK 의 지금 수식 사본(할일 적용 · 저장 없음) — 따로 = 저장한 문서 · 파생 = 다시 지음(옛 엔진 안 돎) ·
|
||||
옛 칸 고침 파생 SK = 400(못 셈 · 855 2-C1)."""
|
||||
if not dsk.own(doc):
|
||||
raise _bad("바탕 참조 단가산출 — 수식 사본 없음")
|
||||
raise _bad(dsk.REF_WHY)
|
||||
clean, whole = _settled(doc, job)
|
||||
if not dc.has(clean): # 옮기기 전 · 새 SK — 저장 때 지을 사본을 미리
|
||||
seed = dsk.settle(clean, whole, job, doc).get(dsk.KEY)
|
||||
if seed is None:
|
||||
raise _bad("수식 사본을 지을 수 없음 — 바탕 로직 · 줄 없음")
|
||||
clean = {**clean, dsk.KEY: seed}
|
||||
box: list = []
|
||||
try:
|
||||
calc.run(clean, whole, catch=box)
|
||||
except sd.DocError as e:
|
||||
raise calc._fail(e) from e
|
||||
got = dsk.copy_of(clean, box[-1] if box else None)
|
||||
return got if got is not None else clean[dsk.KEY]
|
||||
got = dsk.copy_of(clean, whole)
|
||||
if got is None:
|
||||
raise _bad(dsk.OLD_WHY)
|
||||
return got
|
||||
|
||||
|
||||
def answer(copy: dict, sk: dict) -> dict[str, Any]:
|
||||
|
||||
@@ -132,28 +132,32 @@ def _formula_of(doc: dict) -> dict | None:
|
||||
|
||||
|
||||
def line(whole: Any, doc: dict, one: dict) -> dict[str, Any]:
|
||||
"""로직 줄 기준 — 수식 사본 있는 층 셈 = 문서 셈(줄 옵션 = 문서 규칙 · `dc.line_doc`) ·
|
||||
상세 줄 · 재료 = 옛 엔진(화면 그대로 · 802-4b) · 프로젝트 층 · B09(단가 책) · 사본 없음 = 옛 길."""
|
||||
"""로직 줄 기준 — 수식 사본 있는 층 셈 = 문서 셈 한 길(줄 옵션 = 문서 규칙 · `dc.line_doc` · 줄 = 문서
|
||||
답 줄 · 옛 엔진 안 돎 · 855 2-C1) · 프로젝트 층 · B09(단가 책) · 사본 없음 = 옛 길(옛 로직 줄 ·
|
||||
저장소 0 · B9 · 2-E 걸음 몫)."""
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
|
||||
code, rate, picks = one["로직"], one.get("켜쌓기율"), one.get("고름")
|
||||
old = labor.drop_apart(
|
||||
labor.run_line(whole, code, one.get("입력값"), rate, picks), one.get("자재표시")
|
||||
)
|
||||
copy = None if _project() or dsk.OLD.get() else _formula_of(doc)
|
||||
if not copy or getattr(whole, "_tag", None) != (copy.get("판"), copy.get("단가판")):
|
||||
return old
|
||||
got = labor.run_line(whole, code, one.get("입력값"), rate, picks)
|
||||
return labor.drop_apart(got, one.get("자재표시"))
|
||||
base = copy["부름"].get(code)
|
||||
if base is None:
|
||||
return {**old, "기준": None, "까닭": f"수식 문서 없음 「{code}」"}
|
||||
apart = dc.apart_of(one.get("자재표시"), old.get("재료"))
|
||||
return {"기준": None, "줄": [], "재료": [], "까닭": f"수식 문서 없음 「{code}」"}
|
||||
row = whole.logic(code)
|
||||
mats = [] if isinstance(row.get("흐름"), dict) else row.get("호표") or []
|
||||
apart = dc.apart_of(
|
||||
one.get("자재표시"), [{"차례": n} for n, x in enumerate(mats) if x.get("종류") == "재료"]
|
||||
)
|
||||
given = dc.given_of(whole, code, one.get("입력값"))
|
||||
ans = dc.run(dc.line_doc(base, rate, picks, apart), copy, given, whole)
|
||||
if "결과" in ans:
|
||||
return old
|
||||
return {"결과": ans["결과"], "기준": None, "까닭": None}
|
||||
money = dc.money(ans)
|
||||
got = {k: Decimal(str(v)) for k, v in money.items()} if money else None
|
||||
return {**old, "기준": got, "까닭": None if got else dc.why(ans)}
|
||||
lines = ans.get("줄") or []
|
||||
return {"기준": got, "줄": lines, "재료": [], "까닭": None if got else dc.why(ans)}
|
||||
|
||||
|
||||
def combo(expand: Any, doc: dict, trail: tuple[str, ...]) -> dict[str, Any]:
|
||||
|
||||
@@ -39,7 +39,6 @@ from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Block as blk
|
||||
from M02_MasterTemplete import M02_Sangeun_Const as const, M02_Sangeun_Copy as skc
|
||||
from M02_MasterTemplete import M02_Sangeun_Doc as sd, M02_Sangeun_Equation as eqm
|
||||
from M02_MasterTemplete import M02_Sangeun_Views as views
|
||||
|
||||
COSTS = labor.COSTS
|
||||
Ref = dict[str, Any]
|
||||
@@ -245,29 +244,8 @@ def _gap(item: dict, why: str) -> dict:
|
||||
|
||||
# ── 둘째 기초 세부(727-2) ─────────────────────────────────────────────────
|
||||
def sub_run(one: dict, whole: Any, patched: bool = True) -> dict[str, Any]:
|
||||
"""더한줄 로직 하나 = 그 기초 줄(+ 세부 덮개 · 뺀줄)을 엔진으로 — `run_line` 답 + 정체 ·
|
||||
짝잃음 ·
|
||||
바탕판(덮기 전 기초 지문) · 입력 = 채운 줄 값(`_fill`). `patched` False = 덮기 전."""
|
||||
code = str(one["로직"])
|
||||
mine = blk.own(one, whole) # 끊은 기초(796-2e) = 자기 사본 줄 위
|
||||
try:
|
||||
row = mine.logic(code)
|
||||
except Exception as e: # noqa: BLE001 — 엔진 FormulaError
|
||||
return {"기준": None, "까닭": str(e), "정체": [], "짝잃음": [], "바탕판": ""}
|
||||
if any(one.get(k) not in (None, {}, []) for k in sd.BODY): # 넣은 SK 몸(740-1) = 이름 없는 SK
|
||||
keep = ("입력값", *sd.BODY, *(("덮개", "뺀줄") if patched else ()))
|
||||
doc = {"키": "SK-000000", "이름": "줄", "단위": "식", "바탕": {"로직": code}}
|
||||
doc |= {"덮개": {}, "뺀줄": [], "더한줄": [], **{k: one[k] for k in keep if k in one}}
|
||||
try:
|
||||
return {**run(doc, mine), "바탕판": fingerprint(row)}
|
||||
except sd.DocError as e:
|
||||
return {"기준": None, "까닭": str(e), "정체": [], "짝잃음": [], "바탕판": ""}
|
||||
edited, lost = blk.row_of(whole, one)[0:2] if patched else (row, []) # 수식 고침(796-2e)
|
||||
got = sd.patched(edited, one if patched else {})
|
||||
over = _Over(mine, code, {**got["줄"], "키": code})
|
||||
out = labor.run_line(over, code, one.get("입력값"), None, got["고름"] or None)
|
||||
miss = [{"cid": eqm.LOST, "까닭": "수식 고침 못 얹음 — " + " · ".join(lost)}] if lost else []
|
||||
return {**out, "정체": got["정체"], "짝잃음": got["짝잃음"] + miss, "바탕판": fingerprint(row)}
|
||||
"""더한줄 로직 하나(둘째 기초 · 옛 칸) — 수식 사본 없음 = 못 셈 + 까닭(855 2-C1 · 옛 엔진 안 돎)."""
|
||||
return {"기준": None, "까닭": dsk.OLD_WHY, "정체": [], "짝잃음": [], "바탕판": ""}
|
||||
|
||||
|
||||
def _bundled(item: dict, sub: dict) -> dict:
|
||||
@@ -352,6 +330,15 @@ def _bundles(row: dict, whole: Any, expand: Any, trail: tuple) -> None:
|
||||
}
|
||||
|
||||
|
||||
def _row_of(doc: dict, whole: Any) -> dict:
|
||||
"""배 · 바탕판이 읽는 바탕 줄(셈 아님) — 바탕 로직 = 그 줄 · 없음 = 빈 줄(가져온 식 = 그 줄)."""
|
||||
key = (doc.get("바탕") or {}).get("로직")
|
||||
try:
|
||||
return whole.logic(key) if key else sd.empty_row(doc)
|
||||
except Exception as e: # noqa: BLE001 — 없는 로직
|
||||
raise sd.DocError(f"바탕 로직 · {e}") from e
|
||||
|
||||
|
||||
def run(
|
||||
doc: dict,
|
||||
whole: Any,
|
||||
@@ -359,64 +346,90 @@ def run(
|
||||
read: Any = refs.read_ref,
|
||||
expand: Any = None,
|
||||
trail: tuple = (),
|
||||
detail: bool = False,
|
||||
line: bool = False,
|
||||
seen: bool = True,
|
||||
catch: list | None = None,
|
||||
**_opts: Any,
|
||||
) -> dict[str, Any]:
|
||||
"""SK 셈(저장 안 함) — `run_line` 답 + `{1단위, 배, 정체, 짝잃음, 바탕판}` · 줄마다 `cid` ·
|
||||
고친 칸 `덮개`(칸 이름) · `원값`. 틀린 문서 · 순환 = `sd.DocError` ·
|
||||
`detail` = 둘째 기초 세부 펼침(`_detail` · 화면 셈 길만) · 그때 `seen` = 보기 덧칸(750-1) ·
|
||||
`line` = 일위대가 덮개 줄."""
|
||||
"""SK 셈(저장 안 함 · 855 2-C1) = 수식 사본 문서 셈 한 길 — 기준 · 1 단위 · 줄 · 비목 · 끝수 모두
|
||||
문서 답(`M02_Doc_Sk.run`) · 줄 `cid` = 「금액#n」(문서 금액 줄 차례) · 줄 `단위` = 문서 금액 줄 단위 ·
|
||||
수식 사본 없음(바탕 참조 · 옛 칸 덮개 · 더한줄 …) = 못 셈 + 까닭 하나(옛 엔진 안 돎 · 올림 없음) ·
|
||||
굳힌 사본(`M02_Doc_Sk.frozen` — B09 · 구조물 사본) = 옛 길(`_frozen` · B9 걸음 몫).
|
||||
`given` · `_opts`(detail · line · seen) = 옛 길 손님 꼴 — 문서 셈은 안 씀(옛 길도 금액은 문서 답 ·
|
||||
2-E2 에서 부르는 쪽과 같이 걷음). 틀린 단위 환산 = `sd.DocError`."""
|
||||
if dsk.frozen(doc):
|
||||
return _frozen(doc, whole, given, read, expand, trail)
|
||||
whole = skc.over(doc, whole)
|
||||
base = doc.get("바탕") or {}
|
||||
tag = tag_of(whole, base["로직"]) if "로직" in base else (base.get("참조") or {}).get("키")
|
||||
head = {"짝잃음": [], "빠진줄": [], "꼬리표": tag}
|
||||
copy = dsk.copy_of(doc, whole)
|
||||
if copy is None:
|
||||
why = dsk.OLD_WHY if dsk.own(doc) else dsk.REF_WHY
|
||||
none = {"기준": None, "1단위": None, "배": Decimal(1), "바탕판": "", "줄": [], "정체": []}
|
||||
return {**head, **none, "까닭": why, "수식셈": {"셈됨": False, "따로": False, "까닭": why}}
|
||||
row = _row_of(doc, whole)
|
||||
times = ratio_of(doc, row, whole)
|
||||
got = dsk.run(doc, copy, whole)
|
||||
money = dsk.dc.money(got)
|
||||
total = {k: Decimal(str(v)) for k, v in money.items()} if money else None
|
||||
mark = {"셈됨": bool(total), "따로": bool(copy.get("따로"))}
|
||||
if not total:
|
||||
mark["까닭"] = copy["문서"].get("_틀림") or dsk.dc.why(got) or "돈 아닌 문서"
|
||||
src = copy["문서"].get("금액") or []
|
||||
lines = [
|
||||
{**x, "단위": str((src[n] if n < len(src) else {}).get("단위") or ""), "cid": f"금액#{n}"}
|
||||
for n, x in enumerate(got.get("줄") or [])
|
||||
]
|
||||
out = {
|
||||
**head,
|
||||
"기준": total,
|
||||
"1단위": {k: v / times for k, v in total.items()} if total else None,
|
||||
"배": times,
|
||||
"바탕판": fingerprint(row),
|
||||
"줄": lines,
|
||||
"정체": [x["cid"] for x in lines],
|
||||
"끝수": got.get("끝수"),
|
||||
"까닭": None if total or "결과" in got else mark["까닭"],
|
||||
"수식셈": mark,
|
||||
}
|
||||
return out | ({"결과": got["결과"]} if "결과" in got else {})
|
||||
|
||||
|
||||
def _frozen(doc: dict, whole: Any, given: Any, read: Any, expand: Any, trail: tuple) -> dict:
|
||||
"""굳힌 사본 SK(수식 없음) 옛 엔진 셈 — 2-C1 전 `run` 그대로(굳힌 줄 = 덮개 · 더한줄 없음) · B9 몫."""
|
||||
from M02_MasterTemplete.M02_Labor_Expand import Expand
|
||||
|
||||
got = resolve(doc, whole := skc.over(doc, whole), read, trail, given, line)
|
||||
got = resolve(doc, whole := skc.over(doc, whole), read, trail, given)
|
||||
row = {**got["줄"], "호표": [dict(x) for x in got["줄"]["호표"]]}
|
||||
_bundles(row, whole, expand or Expand(whole, read), trail)
|
||||
head = {k: got[k] for k in ("정체", "짝잃음", "바탕판")} | {"배": got["배"]}
|
||||
gaps = {at: x for at, x in enumerate(row["호표"]) if x.get("빠짐")}
|
||||
key = str(doc.get("키") or "SK-000000")
|
||||
over = _Over(whole, key, {**row, "키": key})
|
||||
# 이 SK 줄의 입력만 — 더한줄 로직 입력은 `_fill` 이 따로 채움
|
||||
names = {str(i.get("이름")) for i in row.get("입력") or []}
|
||||
values = {k: v for k, v in {**got["입력값"], **(given or {})}.items() if k in names}
|
||||
out = labor.run_line(over, key, values, got["켜쌓기율"], got["고름"] or None)
|
||||
rates = _rated(row, out.get("줄") or [], got["정체"], got["자재표시"], got["켜쌓기율"])
|
||||
if rates is not None: # 율 더한줄(778-4) — 밑을 넣고 다시
|
||||
head["짝잃음"] = head["짝잃음"] + rates
|
||||
out = labor.run_line(over, key, values, got["켜쌓기율"], got["고름"] or None)
|
||||
eng, ctx = out.get("줄") or [], (over, key, values, got, out.get("재료")) # 802-4a 고친 줄
|
||||
catch is None or catch.append(ctx)
|
||||
seen = (
|
||||
views.text_of(over, key, values, got["고름"], got["정체"], eng) if detail and seen else {}
|
||||
args = (
|
||||
_Over(whole, key, {**row, "키": key}),
|
||||
key,
|
||||
values,
|
||||
got["켜쌓기율"],
|
||||
got["고름"] or None,
|
||||
)
|
||||
covers = doc.get("덮개") or {}
|
||||
lines = []
|
||||
for at, (cid, line) in enumerate(zip(got["정체"], out.get("줄") or [])):
|
||||
mine = covers.get(cid) or {}
|
||||
mark = {"덮개": [k for k in sd.COVER_KEYS if k in mine]} if mine else {}
|
||||
if at in gaps: # 못 셈 줄 = 금액 — · 까닭(725)
|
||||
mark |= {"단가": None, "금액": None, "비목": {}, "까닭": gaps[at]["빠짐"]}
|
||||
hit = re.match(r"^add:#(\d+)$", cid)
|
||||
one = got["채운더한줄"][int(hit[1])] if hit else {}
|
||||
if detail and one.get("종류") == "로직" and at not in gaps:
|
||||
mark |= _detail(one, int(hit[1]), whole)
|
||||
if sd.is_rate(one): # 율 줄 = 율 · 「기준의 %」(화면 % 줄 · `per_unit` 수량 그대로)
|
||||
mark |= {"율": Decimal(str(one["수량"])), "규격": _rate_text(one["고정"]["비율"])}
|
||||
lines.append(
|
||||
{**line, "cid": cid, **mark, **({"원값": mine["원값"]} if "원값" in mine else {})}
|
||||
)
|
||||
out = labor.run_line(*args)
|
||||
lost = _rated(row, out.get("줄") or [], got["정체"], got["자재표시"], got["켜쌓기율"])
|
||||
if lost is not None: # 율 더한줄(778-4) — 밑을 넣고 다시
|
||||
out = labor.run_line(*args)
|
||||
gap = {"단가": None, "금액": None, "비목": {}}
|
||||
lines = [
|
||||
{**line, "cid": cid, **({**gap, "까닭": gaps[at]["빠짐"]} if at in gaps else {})}
|
||||
for at, (cid, line) in enumerate(zip(got["정체"], out.get("줄") or []))
|
||||
]
|
||||
out = labor.drop_apart({**out, "줄": lines}, got["자재표시"])
|
||||
base = out.get("기준")
|
||||
unit = {k: Decimal(str(v)) / got["배"] for k, v in base.items()} if base else None
|
||||
gone = [
|
||||
{"cid": got["정체"][at], "이름": x.get("이름") or "", "까닭": x["빠짐"]}
|
||||
for at, x in gaps.items()
|
||||
]
|
||||
base = doc.get("바탕") or {}
|
||||
tag = tag_of(whole, base["로직"]) if "로직" in base else (base.get("참조") or {}).get("키")
|
||||
ans = {**out, **head, **seen, "1단위": unit, "빠진줄": gone, "꼬리표": tag}
|
||||
return dsk.on_run(doc, ans, ctx) # 수식 사본 SK = 문서 셈 금액(802-4a)
|
||||
head = {k: got[k] for k in ("정체", "바탕판", "배")} | {"짝잃음": got["짝잃음"] + (lost or [])}
|
||||
unit = {k: Decimal(str(v)) / got["배"] for k, v in base.items()} if base else None
|
||||
tag = tag_of(whole, str((doc.get("바탕") or {}).get("로직") or ""))
|
||||
return {**out, **head, "1단위": unit, "빠진줄": gone, "꼬리표": tag}
|
||||
|
||||
|
||||
def _group(item: dict, line: dict) -> str | None:
|
||||
@@ -475,10 +488,10 @@ def unit(doc: dict, whole: Any, expand: Any, trail: tuple) -> dict[str, Any]:
|
||||
"""펼침(`Expand`) 한 칸 — `{이름, 단위, 기준(1 단위), 까닭, 줄, 짝잃음}` · 못 셈 = 까닭."""
|
||||
head = {"이름": doc.get("이름"), "단위": doc.get("단위")}
|
||||
try:
|
||||
got = run(doc, whole, None, expand.read, expand, trail)
|
||||
got = run(doc, whole, None, getattr(expand, "read", refs.read_ref), expand, trail)
|
||||
except sd.DocError as e:
|
||||
return {**head, "기준": None, "까닭": str(e)}
|
||||
gone = got.get("빠진줄") or [] # 쓰는 자리 = 빠진 줄 있으면 통째 기준 없음(부분 값 안 넘김)
|
||||
gone = got.get("빠진줄") or [] # 굳힌 사본 옛 길 — 빠진 줄 있으면 통째 기준 없음
|
||||
why = got.get("까닭") or next((f"「{x['이름']}」 {x['까닭']}" for x in gone), None)
|
||||
why = why or (None if got.get("1단위") else "돈 아닌 로직")
|
||||
times = got["배"]
|
||||
|
||||
@@ -317,7 +317,7 @@ def answer(got: dict, clean: dict, raw: Any, given: dict | None, trail: tuple) -
|
||||
"""`M02_Sangeun_Calc.calc_doc` 답 — 옛 답 + `원래` · `시트`."""
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
|
||||
out = {**calc.views.finish(calc.per_unit(got, clean)), "머리": calc.head_of(clean)}
|
||||
out = {**calc.per_unit(got, clean), "머리": calc.head_of(clean)}
|
||||
return calc.labor._json(imp.more(out | sheet(out, clean, raw, given, trail), clean))
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"지문": {
|
||||
"키": "e68369418202e5ee",
|
||||
"calc_user": "6d74551273d6735f",
|
||||
"daega_inputs": "0ef81c80bc45ae0b",
|
||||
"daega_inputs": "d26099b92d7d0a1b",
|
||||
"수요": "f793204cf95c45c4",
|
||||
"산근 값": "c486d041a3246ffb",
|
||||
"산근 글": "a21b34ec13661f0c",
|
||||
|
||||
@@ -6,15 +6,12 @@
|
||||
[단가산출로 저장] = 새 SK + 참조 줄 · 같은 값 · 단위 빈칸 400 · 덮개 없는 줄 = 옛 값.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from resources.tester.test_m02_labor_ref import MINE, world # noqa: F401 — 같은 임시 층
|
||||
|
||||
PCT = "GC001109" # 원/㎡ · 인력 둘(LB000036 · LB000002) + 「노무비 * 3 / 100」
|
||||
@@ -40,66 +37,6 @@ def _value(folder, key):
|
||||
return refs.Expand(_whole(), given=given)(ref)
|
||||
|
||||
|
||||
def test_logic_line_cover_in_precombo(world):
|
||||
"""사전조합 로직 줄 덮개 = 같은 덮개 SK 값 · 손셈(품 0.5 × 단가 + 둘째 줄 · 3 % 덧줄)."""
|
||||
bare = labor.run_line(_whole(), PCT, {})
|
||||
sc = _sc(world["personal"], [{"로직": PCT, "패치": COVER}])
|
||||
with store.at(world["personal"]):
|
||||
kept = store.read("precombo", sc)["문서"]["담은로직"][0]
|
||||
assert kept["패치"] == COVER
|
||||
got = _value(world["personal"], sc)["기준"]
|
||||
cut = labor.mcut.down # 751-3 — 줄 0.1 원 · 비목 합 1 원 버림
|
||||
labor_sum = cut(Decimal("0.5") * Decimal(str(bare["줄"][0]["단가"])), 1) + Decimal(
|
||||
str(bare["줄"][1]["금액"])
|
||||
)
|
||||
assert got["노무비"] == pytest.approx(cut(labor_sum, 0))
|
||||
assert got["경비"] == pytest.approx(labor_sum * 3 / 100, abs=1)
|
||||
|
||||
|
||||
def test_line_pick_by_order_stays_after_drop(world):
|
||||
"""줄 고름 = 바탕 호표 차례(2) · 패치 뺀줄로 첫 재료 줄을 빼도 그 자재가 그 줄에."""
|
||||
import master_pick as mp
|
||||
|
||||
whole = _whole()
|
||||
row = whole.logic(TWO_MATS)
|
||||
item = row["호표"][2]
|
||||
want = mp.search(whole, item["요소"], {}, item.get("단위"))[1]
|
||||
one = {
|
||||
"로직": TWO_MATS,
|
||||
"고름": {"2": want},
|
||||
"자재표시": {"2": {"별도계상": "직접계산"}},
|
||||
"패치": {"뺀줄": ["material:" + row["호표"][1]["이름"] + "#0"]},
|
||||
}
|
||||
with store.at(world["personal"]):
|
||||
doc = labor.clean({"담은로직": [one]})
|
||||
got = labor.calc(doc, {})["줄"][0]
|
||||
picked = [x for x in got["줄"] if x.get("품목")]
|
||||
assert [x["품목"]["키"] for x in picked] == [want]
|
||||
|
||||
|
||||
def test_ref_line_cover_only_that_line(world):
|
||||
"""SK 참조 줄 덮개 = 그 줄만 · SK 원본 · 다른 줄 값 그대로."""
|
||||
with store.at(world["personal"]):
|
||||
sk = refs.create(
|
||||
"sangeun", {"이름": "밑", "단위": "㎡", "바탕": {"로직": PCT}, "더한줄": []}
|
||||
)["이름"]
|
||||
before = store.read("sangeun", sk)["판"]
|
||||
ref = {**MINE, "키": sk}
|
||||
sc = _sc(
|
||||
world["personal"],
|
||||
[{"참조": ref, "수량": {"손": 1}, "패치": COVER}, {"로직": "GC001111", "수량": {"손": 1}}],
|
||||
)
|
||||
inner = _value(world["personal"], sc)["안"]
|
||||
plain = _value(world["personal"], _sc(world["personal"], [{"참조": ref}]))["기준"]
|
||||
covered = calc.calc_doc(
|
||||
{"키": "SK-000999", "이름": "x", "단위": "㎡", "바탕": {"로직": PCT}, **COVER}
|
||||
)
|
||||
assert inner[0]["기준"]["계"] == pytest.approx(Decimal(str(covered["1단위"]["계"])))
|
||||
assert inner[0]["기준"]["계"] != plain["계"]
|
||||
with store.at(world["personal"]):
|
||||
assert store.read("sangeun", sk)["판"] == before
|
||||
|
||||
|
||||
def test_refusals(world):
|
||||
with store.at(world["personal"]):
|
||||
with pytest.raises(store.StoreError, match="단위가 빔"):
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
# ruff: noqa: F811 — 임시 층 fixture(world)를 test_m02_labor_ref 에서 받아 씀
|
||||
"""M02 단가산출(SK) 엔진 입력 덧칸(PLAN 715-1b · `master_pick`) — 고친 줄 값 = 손셈.
|
||||
|
||||
줄 단가 덮개 = 손 단가 · 로직 줄 노 · 재 · 경 덮개 = 값묶음(일부면 엔진 값 위) ·
|
||||
덧줄 % 가 덮인 값에서 다시 셈 · 더한줄 참조(SK · SC) · 고정 = 1 단위 묶음 · 덧칸 없는 줄 = 엔진 값.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from resources.tester.test_m02_labor_ref import MINE, world # noqa: F401 — 같은 임시 층
|
||||
|
||||
PCT = "GC001109" # 원/㎡ · 인력 둘 + 「노무비 * 3 / 100」
|
||||
SUB = "GC000999" # 원/주 · 인력 둘 + 로직 줄(GC000275)
|
||||
|
||||
|
||||
def _whole():
|
||||
return m01.loaded()[1]
|
||||
|
||||
|
||||
def _run(**doc):
|
||||
from M02_MasterTemplete import M02_Sangeun_Doc as sd
|
||||
|
||||
whole = _whole()
|
||||
clean = sd.clean({"키": "SK-000001", "이름": "시험", "단위": "㎡", **doc}, None, whole)
|
||||
return labor._json(calc.run(clean, whole))
|
||||
|
||||
|
||||
def test_price_cover_is_hand_price_and_pct_follows():
|
||||
bare = labor.run_line(_whole(), PCT, {})
|
||||
first, second = bare["줄"][0], bare["줄"][1]
|
||||
got = _run(바탕={"로직": PCT}, 덮개={"labor:LB000036#0": {"labor": 200000}})
|
||||
line = got["줄"][0]
|
||||
assert line["단가"] == 200000 and line["출처"] == "손 단가"
|
||||
cut = labor.mcut.down # 751-3 — 줄 0.1 원 · 비목 합 1 원 버림
|
||||
want = cut(Decimal(str(first["수량"])) * 200000, 1) + Decimal(str(second["금액"]))
|
||||
assert got["기준"]["노무비"] == pytest.approx(float(cut(want, 0)))
|
||||
assert got["기준"]["경비"] == pytest.approx(float(want * 3 / 100), abs=1)
|
||||
|
||||
|
||||
def test_bundle_cover_on_logic_line_partial():
|
||||
bare = labor.run_line(_whole(), SUB, {})
|
||||
sub = bare["줄"][2]
|
||||
got = _run(바탕={"로직": SUB}, 단위="주", 덮개={"logic:GC000275#0": {"expense": 1000}})
|
||||
line = got["줄"][2]
|
||||
qty = Decimal(str(sub["수량"]))
|
||||
assert line["비목"]["경비"] == pytest.approx(float(qty * 1000))
|
||||
assert line["비목"]["노무비"] == pytest.approx(
|
||||
float(sub["비목"]["노무비"])
|
||||
) # 안 덮은 칸 = 엔진 값
|
||||
|
||||
|
||||
def test_untouched_lines_same_as_engine():
|
||||
bare = labor.run_line(_whole(), SUB, {})
|
||||
got = _run(바탕={"로직": SUB}, 단위="주") # 바탕 단위(728-2 — 성격 다르면 계수 칸)
|
||||
assert got["기준"]["계"] == pytest.approx(float(bare["기준"]["계"]))
|
||||
|
||||
|
||||
def test_added_ref_and_fixed_lines(world):
|
||||
"""더한줄 = SK 참조 2 · 고정 줄 1 — 값 = 2 × 그 SK 1 단위 + 고정 단가."""
|
||||
with store.at(world["personal"]):
|
||||
sk = refs.create(
|
||||
"sangeun", {"이름": "밑", "단위": "㎡", "바탕": {"로직": PCT}, "더한줄": []}
|
||||
)["이름"]
|
||||
unit = calc.calc_doc(store.read("sangeun", sk)["문서"])["1단위"]["계"]
|
||||
top = refs.create(
|
||||
"sangeun",
|
||||
{
|
||||
"이름": "위",
|
||||
"단위": "식",
|
||||
"바탕": None,
|
||||
"더한줄": [
|
||||
{"참조": {**MINE, "키": sk}, "수량": 2},
|
||||
{"고정": {"이름": "운반", "단위": "식", "단가": {"경비": 5000}}, "수량": 1},
|
||||
],
|
||||
},
|
||||
)["이름"]
|
||||
got = calc.calc_doc(store.read("sangeun", top)["문서"])
|
||||
assert got["기준"]["계"] == pytest.approx(unit * 2 + 5000, abs=1)
|
||||
expense = labor.run_line(_whole(), PCT, {})["기준"]["경비"]
|
||||
assert got["기준"]["경비"] == pytest.approx(5000 + 2 * float(expense), abs=1)
|
||||
|
||||
|
||||
def test_added_material_counts_unless_apart():
|
||||
"""사용자가 더한 재료 줄 = 기본 계 안(재료비 · 계에 더함) · 줄 「별도계상」 칸만 계 밖(재료 목록만)."""
|
||||
one = {"종류": "재료", "요소": "MT000010", "수량": 3, "단가": 1200}
|
||||
bare = _run(바탕={"로직": PCT})
|
||||
inside = _run(바탕={"로직": PCT}, 더한줄=[one])
|
||||
assert inside["기준"]["재료비"] == pytest.approx(bare["기준"]["재료비"] + 3600)
|
||||
assert inside["기준"]["계"] == pytest.approx(bare["기준"]["계"] + 3600, abs=1)
|
||||
assert any(x["cid"] == "add:#0" for x in inside["줄"])
|
||||
apart = _run(바탕={"로직": PCT}, 더한줄=[{**one, "별도계상": True}])
|
||||
assert apart["기준"]["계"] == pytest.approx(bare["기준"]["계"])
|
||||
assert not any(x["cid"] == "add:#0" for x in apart["줄"])
|
||||
assert any(m["금액"] == pytest.approx(3600) for m in apart["재료"])
|
||||
@@ -5,8 +5,6 @@
|
||||
바탕 · 사전조합에 SK 넣기 = 펼쳐 담음(740-1 · 원본 지워도 그대로) · 층 복사 왕복 같은 값.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
@@ -46,109 +44,6 @@ def _bare(code):
|
||||
return labor.run_line(_whole(), code, {})
|
||||
|
||||
|
||||
def test_qty_cover_hand_and_pct_recomputed(world):
|
||||
"""품 덮개 = 손셈 · 「노무비 * 3 / 100」 덧줄 다시 셈 · 원값 = 서버가 셈."""
|
||||
bare = _bare(PCT)
|
||||
first, second = bare["줄"][0], bare["줄"][1]
|
||||
key = _sk(
|
||||
world["personal"], 바탕={"로직": PCT}, 덮개={"labor:LB000036#0": {"qty": 0.5, "원값": 9}}
|
||||
)
|
||||
doc = _doc(world["personal"], key)
|
||||
assert doc["덮개"]["labor:LB000036#0"]["원값"]["qty"] == pytest.approx(float(first["수량"]))
|
||||
assert len(doc["바탕판"]) == 16
|
||||
got = _calc(world["personal"], key)
|
||||
cut = calc.labor.mcut.down # 751-3 — 줄 0.1 원 · 비목 합 1 원 버림
|
||||
labor_sum = cut(Decimal("0.5") * Decimal(str(first["단가"])), 1) + Decimal(str(second["금액"]))
|
||||
assert got["기준"]["노무비"] == pytest.approx(float(cut(labor_sum, 0)))
|
||||
assert got["기준"]["경비"] == pytest.approx(float(labor_sum * 3 / 100), abs=1)
|
||||
assert got["줄"][0]["덮개"] == ["qty"] and got["줄"][0]["cid"] == "labor:LB000036#0"
|
||||
assert got["짝잃음"] == []
|
||||
# 덧줄 율 덮개 = 5 %
|
||||
key = _sk(
|
||||
world["personal"],
|
||||
바탕={"로직": PCT},
|
||||
덮개={"pct:" + bare["줄"][2]["이름"] + "#0": {"qty": 5}},
|
||||
)
|
||||
got = _calc(world["personal"], key)
|
||||
assert got["기준"]["경비"] == pytest.approx(float(bare["기준"]["노무비"]) * 0.05, abs=1)
|
||||
|
||||
|
||||
def test_drop_then_pick_stays_on_its_line(world):
|
||||
"""뺀줄 뒤 고름 제자리 — 둘째 재료 줄을 고른 자재가 첫 재료 줄을 뺀 뒤에도 그 줄 품목."""
|
||||
import master_pick as mp
|
||||
|
||||
whole = _whole()
|
||||
row = whole.logic(TWO_MATS)
|
||||
item = row["호표"][2]
|
||||
picks = mp.search(whole, item["요소"], {}, item.get("단위"))
|
||||
want = picks[1] if len(picks) > 1 else picks[0]
|
||||
first_cid = "material:" + row["호표"][1]["이름"] + "#0"
|
||||
second_cid = "material:" + item["이름"] + "#0"
|
||||
key = _sk(
|
||||
world["personal"],
|
||||
단위="m",
|
||||
바탕={"로직": TWO_MATS},
|
||||
뺀줄=[first_cid],
|
||||
고름={second_cid: want},
|
||||
자재표시={second_cid: {"별도계상": "직접계산"}}, # 기본 = 별도계상(222-1) 줄 빠짐
|
||||
)
|
||||
got = _calc(world["personal"], key)
|
||||
names = [x["이름"] for x in got["줄"]]
|
||||
assert row["호표"][1]["이름"] not in names
|
||||
line = next(x for x in got["줄"] if x["cid"] == second_cid)
|
||||
assert line["품목"]["키"] == want
|
||||
|
||||
|
||||
def test_lost_cover_kept_and_listed(world):
|
||||
key = _sk(world["personal"], 바탕={"로직": PCT}, 덮개={"labor:LB999999#0": {"qty": 1}})
|
||||
got = _calc(world["personal"], key)
|
||||
assert got["짝잃음"][0]["cid"] == "labor:LB999999#0"
|
||||
assert "labor:LB999999#0" in _doc(world["personal"], key)["덮개"]
|
||||
assert got["기준"]["계"] == pytest.approx(float(_bare(PCT)["기준"]["계"]))
|
||||
|
||||
|
||||
def test_chain_base_flattened_delete_free(world):
|
||||
"""바탕 SK 넣기(740-1) = 펼쳐 담음 — 바탕 = M01 기초 · 위 덮개 겹침 · 값 같음 ·
|
||||
원본 지워도 그대로."""
|
||||
a = _sk(world["personal"], 바탕={"로직": PCT})
|
||||
b = _sk(
|
||||
world["personal"], 바탕={"참조": {**MINE, "키": a}}, 덮개={"labor:LB000002#0": {"qty": 0}}
|
||||
)
|
||||
assert _doc(world["personal"], b)["바탕"] == {"로직": PCT}
|
||||
got = _calc(world["personal"], b)
|
||||
bare = _bare(PCT)
|
||||
assert got["기준"]["노무비"] == pytest.approx(
|
||||
float(calc.labor.mcut.down(bare["줄"][0]["금액"], 0))
|
||||
)
|
||||
with store.at(world["personal"]):
|
||||
store.delete("sangeun", a) # 쓰는 곳 없음(서로 독립)
|
||||
assert _calc(world["personal"], b)["기준"] == got["기준"]
|
||||
|
||||
|
||||
def test_precombo_holds_sangeun(world):
|
||||
"""사전조합에 SK 넣기(811-1) = SK 참조 한 행 · 1 단위 값 × 수량 · 쓰는 SK 는 못 지움."""
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
|
||||
sk = _sk(world["personal"], 바탕={"로직": PCT}, 덮개={"labor:LB000036#0": {"qty": 0.5}})
|
||||
one = _calc(world["personal"], sk)["1단위"]["계"]
|
||||
with store.at(world["personal"]):
|
||||
sc = refs.create(
|
||||
"precombo",
|
||||
{
|
||||
"이름": "조합",
|
||||
"단위": "㎡",
|
||||
"담은로직": [{"참조": {**MINE, "키": sk}, "수량": {"손": 2}}],
|
||||
},
|
||||
)["이름"]
|
||||
line = store.read("precombo", sc)["문서"]["담은로직"][0]
|
||||
assert line["참조"] == {**MINE, "키": sk} # 811-1 SK 줄 = 참조 한 행(안 펼침)
|
||||
with pytest.raises(store.StoreError, match="쓰는 곳"):
|
||||
store.delete("sangeun", sk)
|
||||
pill = {f"{refs.ref_id({**MINE, '키': sc})}#0": 2} # 723-1 안 줄 수량 = 쓰는 쪽 알약
|
||||
got = labor.calc({"담은로직": [{"참조": {**MINE, "키": sc}, "수량": {"손": 1}}]}, pill)
|
||||
assert got["반영합"]["계"] == pytest.approx(one * 2, abs=1)
|
||||
|
||||
|
||||
def test_layer_copy_round_trip(world):
|
||||
"""개인 B(바탕 = 개인 A) → 회사로 복사 = 펼친 몸(바탕 = 기초 · 본뜬) → 개인으로 다시 =
|
||||
같은 값."""
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
"""717-2b M02 단가산출 상세 · 고침 지킴 시험 — 순수 꼴(node) · 글 · 서버 저장 왕복(임시 storage).
|
||||
|
||||
- 공용 상세 고침(724-1 `setLineCover`) → SK 덮개(qty · 배율 · 비목 칸 · 원값 곁 글) ·
|
||||
더한줄 수량 · 단가 · 뺀줄 · 되살림
|
||||
- SK 셈 답 → 공용 상세 줄(`hoView` — 정체 차례 · 바탕 줄 그대로 · 더한줄 · 고침 열쇠) ·
|
||||
계산서 묶음 = 표 줄 그대로
|
||||
- 화면 문서 꼴이 서버 저장(`clean_doc`)을 지나고 서버가 원값 · 바탕판을 다시 적음 · 셈 = 손셈
|
||||
- 상세 = M01 상세 부품(M02 길) · 부품 상자만 · 마스터 이동 단추 = 등록 없으면 숨김
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from resources.tester.test_m02_labor_ref import world # noqa: F401 — 같은 임시 층
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
M02 = ROOT / "M02_MasterTemplete"
|
||||
BASE = "GC000278"
|
||||
|
||||
|
||||
def _text(p: Path) -> str:
|
||||
return p.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_화면_문서_꼴_서버_저장_셈(world): # noqa: F811 — 가져온 fixture
|
||||
"""화면 꼴(덮개 + 원값 곁 글 · 로직 줄 나눈 단가 · 더한줄 · 뺀줄) → 저장 · 셈 = 손셈."""
|
||||
mine = world["personal"]
|
||||
with store.at(mine):
|
||||
plain = calc.calc_doc(
|
||||
{"키": "SK-000000", "이름": "t", "단위": "㎥", "바탕": {"로직": BASE}}
|
||||
)
|
||||
lines = {x["cid"]: x for x in plain["줄"]}
|
||||
a, g = lines["labor:LB000018#0"], lines["logic:GC000267#0"]
|
||||
parts = {k: Decimal(str(v)) for k, v in g["비목"].items()}
|
||||
whole_amount = sum(parts.values())
|
||||
split = {
|
||||
{"노무비": "labor", "재료비": "material", "경비": "expense"}[k]: float(
|
||||
round(Decimal(90000) * v / whole_amount, 4)
|
||||
)
|
||||
for k, v in parts.items()
|
||||
}
|
||||
doc = {
|
||||
"이름": "717-2b 시험",
|
||||
"단위": "㎥",
|
||||
"바탕": {"로직": BASE},
|
||||
"덮개": {
|
||||
"labor:LB000018#0": {"qty": 0.02, "원값": {"qty": 1, "단가": 1}}, # 화면 곁 글
|
||||
"logic:GC000267#0": {**split, "원값": {"qty": 9}},
|
||||
},
|
||||
"뺀줄": ["labor:LB000002#1"],
|
||||
"더한줄": [
|
||||
{"종류": "인력", "요소": "LB000002", "이름": "보통인부", "단위": "인", "수량": 0.01}
|
||||
],
|
||||
}
|
||||
key = refs.create("sangeun", doc)["이름"]
|
||||
saved = store.read("sangeun", key)["문서"]
|
||||
got = calc.calc_doc(saved)
|
||||
cover = saved["덮개"]["labor:LB000018#0"]
|
||||
assert cover["원값"]["qty"] == pytest.approx(a["수량"]) # 서버가 다시 적음(화면 값 버림)
|
||||
assert saved["바탕판"] == plain["바탕판"] and saved["뺀줄"] == ["labor:LB000002#1"]
|
||||
by = {x["cid"]: x for x in got["줄"]}
|
||||
assert "labor:LB000002#1" not in by
|
||||
assert by["labor:LB000018#0"]["금액"] == pytest.approx(0.02 * a["단가"])
|
||||
# 751-3 — 비목마다 0.1 원 버림(셋)
|
||||
assert by["logic:GC000267#0"]["금액"] == pytest.approx(g["수량"] * 90000, abs=0.3)
|
||||
added = by["add:#0"] # 더한 보통인부 = 바탕 보통인부 단가 × 0.01
|
||||
assert added["수량"] == pytest.approx(0.01)
|
||||
assert added["단가"] == pytest.approx(lines["labor:LB000002#0"]["단가"])
|
||||
gap = sum(x["금액"] for x in got["줄"]) - got["기준"]["계"] # 751-3 비목마다 1 원 버림
|
||||
assert -1e-6 <= gap < 3
|
||||
@@ -13,7 +13,6 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
M02 = ROOT / "M02_MasterTemplete"
|
||||
@@ -81,18 +80,6 @@ def _fx(name: str, unit: str, code: str) -> dict:
|
||||
def test_721_2_인력_재료_서버가_받아_셈():
|
||||
whole = labor.m01.loaded()[1]
|
||||
wage = whole.get(LB)["값"]
|
||||
sk = calc.calc_doc(
|
||||
{
|
||||
"키": "SK-000001",
|
||||
"이름": "시험",
|
||||
"단위": "㎡",
|
||||
"바탕": None,
|
||||
"더한줄": [
|
||||
{"종류": "인력", "요소": LB, "이름": "석공", "단위": "인", "수량": 1},
|
||||
{"종류": "재료", "요소": MT, "이름": "합판", "단위": "㎡", "수량": 1},
|
||||
],
|
||||
}
|
||||
)["1단위"]
|
||||
doc = labor.clean(
|
||||
{
|
||||
"담은로직": [
|
||||
@@ -102,8 +89,7 @@ def test_721_2_인력_재료_서버가_받아_셈():
|
||||
}
|
||||
)
|
||||
got = labor.calc(doc, {})
|
||||
assert sk["노무비"] == pytest.approx(wage) and sk["재료비"] > 0
|
||||
assert got["반영합"]["계"] == pytest.approx(sk["계"])
|
||||
assert got["반영합"]["노무비"] == pytest.approx(wage) and got["반영합"]["재료비"] > 0
|
||||
assert [ln["이은"] for ln in got["줄"]] == [["노무비"], ["재료비"]]
|
||||
|
||||
|
||||
@@ -153,17 +139,7 @@ def test_736_3_기계_고정_줄_금액():
|
||||
"단가": {k: got[k] for k in ("노무비", "재료비", "경비")},
|
||||
"이음": {"노임": None, "자재": None, "기계": EQ},
|
||||
}
|
||||
sk = calc.calc_doc(
|
||||
{
|
||||
"키": "SK-000001",
|
||||
"이름": "시험",
|
||||
"단위": "시간",
|
||||
"바탕": None,
|
||||
"더한줄": [{"고정": fx, "이름": got["이름"], "단위": "시간", "수량": 1}],
|
||||
}
|
||||
)["1단위"]
|
||||
doc = labor.clean({"담은로직": [{"로직": "", "고정": fx, "수량": {"손": 1}}]})
|
||||
assert sk["계"] == pytest.approx(got["계"])
|
||||
assert labor.calc(doc, {})["반영합"]["계"] == pytest.approx(got["계"])
|
||||
find = _text(M02 / "M02_MasterTemplete_Find_Pick.ts")
|
||||
assert (
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
"""725-1 · 725-2 단가산출 [항목 추가] 못 셈 줄 — 더한줄 로직 입력 = 공통 옵션 › 로직 기본값 ·
|
||||
그래도 빈 입력 · 수량 없는 일위대가 줄 = 그 줄만 금액 없음 + 까닭 · 나머지 셈 계속(임시 storage)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from resources.tester.test_m02_labor_ref import MINE, world # noqa: F401 — 같은 임시 층
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
GF = "GF000099" # 측구터파기 토사 · 입력 지역 · 보정작업
|
||||
PCT = "GC001109" # 입력 없음 · 인력 둘 + 덧줄 %
|
||||
GF_LINE = {"종류": "로직", "로직": GF, "입력값": {}, "수량": 1}
|
||||
PCT_LINE = {"종류": "로직", "로직": PCT, "입력값": {}, "수량": 1}
|
||||
|
||||
|
||||
def _sk(folder, **doc):
|
||||
with store.at(folder):
|
||||
made = refs.create("sangeun", {"이름": "sub7임시", "단위": "㎥", "더한줄": [], **doc})
|
||||
return store.read("sangeun", made["이름"])["문서"]
|
||||
|
||||
|
||||
def _run(folder, doc, given=None):
|
||||
with store.at(folder):
|
||||
return calc.calc_doc(doc, given)
|
||||
|
||||
|
||||
def _line(got, cid):
|
||||
return next(x for x in got["줄"] if x["cid"] == cid)
|
||||
|
||||
|
||||
def _m01(code, values):
|
||||
return float(labor.run_line(m01.loaded()[1], code, values, None, None)["기준"]["계"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("given", "want"),
|
||||
[
|
||||
(None, {"지역": "전국평균", "보정작업": "해당 없음"}), # 로직 기본값
|
||||
({"지역": "서울"}, {"지역": "서울", "보정작업": "해당 없음"}), # 공통 옵션 › 기본값
|
||||
],
|
||||
)
|
||||
def test_added_logic_takes_common_then_default(world, given, want): # noqa: F811
|
||||
"""입력 있는 로직 더한줄(입력값 {}) = 공통 옵션 넣은 M01 셈 · 계 = 바탕 + 그 줄."""
|
||||
doc = _sk(world["personal"], 바탕={"로직": GF}, 더한줄=[GF_LINE])
|
||||
plain = _sk(world["personal"], 바탕={"로직": GF})
|
||||
got, bare = _run(world["personal"], doc, given), _run(world["personal"], plain, given)
|
||||
one = _m01(GF, want)
|
||||
assert got["빠진줄"] == [] and not got.get("까닭")
|
||||
assert _line(got, "add:#0")["금액"] == pytest.approx(one, rel=1e-9)
|
||||
assert got["기준"]["계"] - bare["기준"]["계"] == pytest.approx(one, rel=1e-9)
|
||||
assert doc["더한줄"][0]["입력값"] == {} # 문서에 안 적음 — 공통 옵션을 바꾸면 따라감
|
||||
|
||||
|
||||
def test_line_without_input_only_that_line_drops(world, monkeypatch): # noqa: F811
|
||||
"""기본값도 없는 입력 = 그 줄만 금액 — · 까닭 · 계 = 나머지 · 쓰는 자리 = 기준 없음."""
|
||||
monkeypatch.setattr(calc, "_defaults", lambda whole, code: {})
|
||||
doc = _sk(world["personal"], 더한줄=[GF_LINE, PCT_LINE])
|
||||
rest = _sk(world["personal"], 더한줄=[PCT_LINE])
|
||||
got, want = _run(world["personal"], doc), _run(world["personal"], rest)
|
||||
gap = _line(got, "add:#0")
|
||||
assert gap["금액"] is None and gap["까닭"] == "입력 「지역」 없음"
|
||||
assert got["빠진줄"] == [{"cid": "add:#0", "이름": gap["이름"], "까닭": "입력 「지역」 없음"}]
|
||||
assert gap["이름"] # 이름 남음 — 화면 줄 빼기 자리
|
||||
assert got["기준"]["계"] == pytest.approx(float(want["기준"]["계"]), rel=1e-9)
|
||||
assert _line(got, "add:#1")["금액"] == pytest.approx(float(want["기준"]["계"]), rel=1e-9)
|
||||
with store.at(world["personal"]):
|
||||
up = refs.Expand(m01.loaded()[1])({**MINE, "키": doc["키"]})
|
||||
assert up["기준"] is None and "입력 「지역」 없음" in up["까닭"]
|
||||
|
||||
|
||||
def test_precombo_in_sk_flattened_no_gap(world): # noqa: F811
|
||||
"""740-1 — SK 에 넣은 일위대가 = 줄마다 더한줄로 펼쳐 담음(수량 = 넣은 수 × 1) · 빠진 줄 없음."""
|
||||
with store.at(world["personal"]):
|
||||
sc = refs.create(
|
||||
"precombo", {"이름": "sub7임시SC", "단위": "㎥", "담은로직": [{"로직": PCT}]}
|
||||
)
|
||||
line = {"참조": {**MINE, "키": sc["이름"]}, "수량": 2}
|
||||
doc = _sk(world["personal"], 더한줄=[line, PCT_LINE])
|
||||
rest = _sk(world["personal"], 더한줄=[PCT_LINE])
|
||||
got, want = _run(world["personal"], doc), _run(world["personal"], rest)
|
||||
assert doc["더한줄"][0]["로직"] == PCT and doc["더한줄"][0]["본뜬"]["키"] == sc["이름"]
|
||||
assert got["빠진줄"] == []
|
||||
assert got["기준"]["계"] == pytest.approx(3 * float(want["기준"]["계"]), rel=1e-9)
|
||||
|
||||
|
||||
def test_screen_shows_dropped_lines():
|
||||
"""화면 — 빠진 줄 띠(이름 · 까닭) · 금액 없는 줄 계산서 금액 —."""
|
||||
ts = (ROOT / "M02_MasterTemplete" / "M02_MasterTemplete_Sangeun_Detail.ts").read_text("utf-8")
|
||||
assert "ans?.빠진줄" in ts and 'L("M02_SangeunGap")' in ts
|
||||
|
||||
|
||||
def test_no_base_common_option_seoul(world): # noqa: F811
|
||||
"""725-6 — 바탕 없는 SK 도 공통 옵션(지역 서울) 따라감 = M01 셈."""
|
||||
doc = _sk(world["personal"], 더한줄=[GF_LINE])
|
||||
got = _run(world["personal"], doc, {"지역": "서울"})
|
||||
assert got["빠진줄"] == [], got
|
||||
assert got["기준"], {k: v for k, v in got.items() if k != "줄"}
|
||||
assert got["기준"]["계"] == pytest.approx(_m01(GF, {"지역": "서울", "보정작업": "해당 없음"}))
|
||||
assert float(got["기준"]["계"]) == 5660 # 751-3 끝수 · 840-5 굴착기 조종원 35,412 → 59,020/시간
|
||||
@@ -16,8 +16,6 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Item_Prices as prices
|
||||
from M02_MasterTemplete import M02_Item_Source as source
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Logic_Standard as standard
|
||||
@@ -104,83 +102,6 @@ def _m01(code, values=None):
|
||||
return float(labor.run_line(m01.loaded()[1], code, values or {}, None, None)["기준"]["계"])
|
||||
|
||||
|
||||
def test_727_2_첫_기초_바탕_세부_줄(world): # noqa: F811
|
||||
doc = _sk(world["personal"], 바탕={"로직": GF})
|
||||
got = _run(world["personal"], doc)
|
||||
assert _line(got, "labor:LB000002#0")["수량"] == pytest.approx(0.023)
|
||||
assert _line(got, "logic:GC000267#0")["수량"] == pytest.approx(0.01546, abs=1e-5)
|
||||
assert got["꼬리표"] == "9-12-1"
|
||||
|
||||
|
||||
def test_727_2_기초_둘_세부_펼침_계(world): # noqa: F811
|
||||
doc = _sk(world["personal"], 바탕={"로직": GF}, 더한줄=[SECOND])
|
||||
bare = _run(world["personal"], _sk(world["personal"], 바탕={"로직": GF}))
|
||||
got = _run(world["personal"], doc)
|
||||
add = _line(got, "add:#0")
|
||||
assert add["꼬리표"] == "3-2-1" and add["바탕판"] and add["뺀세부"] == []
|
||||
sub = {x["cid"]: x for x in add["펼침"]}
|
||||
assert list(sub) == [
|
||||
"add:#0/labor:LB000036#0",
|
||||
"add:#0/labor:LB000002#0",
|
||||
"add:#0/pct:공구손료 및 경장비#0",
|
||||
]
|
||||
assert sub["add:#0/labor:LB000036#0"]["수량"] == pytest.approx(0.018)
|
||||
# 머리 = 수량 × 기초 끝수 계(751-3 · 비목 1 원 · 줄 0.1 원 버림) — 펼침 합과 비목마다 수량 × 1 원 안
|
||||
q = add["수량"]
|
||||
assert sum(x["금액"] for x in add["펼침"]) == pytest.approx(add["금액"], abs=0.3 + 3 * q)
|
||||
assert add["금액"] == pytest.approx(_m01(PCT), rel=1e-9)
|
||||
assert got["기준"]["계"] == pytest.approx(bare["기준"]["계"] + _m01(PCT), rel=1e-9)
|
||||
with store.at(world["personal"]): # 펼침 없는 셈(쓰는 자리) = 같은 계
|
||||
plain = calc.run(doc, m01.loaded()[1])
|
||||
assert float(plain["기준"]["계"]) == pytest.approx(got["기준"]["계"], rel=1e-9)
|
||||
|
||||
|
||||
def test_727_2_둘째_기초_덮개_뺀줄_저장(world): # noqa: F811
|
||||
one = {**SECOND, "수량": 2, "덮개": COVER, "뺀줄": DROP}
|
||||
doc = _sk(world["personal"], 바탕={"로직": GF}, 더한줄=[one])
|
||||
saved = doc["더한줄"][0]
|
||||
assert saved["덮개"]["labor:LB000036#0"] == {
|
||||
"qty": 0.036,
|
||||
"원값": {"qty": 0.018, "단가": 233250},
|
||||
}
|
||||
assert saved["뺀줄"] == DROP and saved["바탕판"]
|
||||
got = _run(world["personal"], doc)
|
||||
add = _line(got, "add:#0")
|
||||
cut = labor.mcut.down # 751-3 — 기초 줄 0.1 원 · 비목 합 1 원 → × 수량 0.1 원
|
||||
want = cut(2 * cut(cut(0.036 * 233250, 1) + cut(0.012 * 172068, 1), 0), 1)
|
||||
assert add["금액"] == pytest.approx(float(want), rel=1e-9)
|
||||
sub = {x["cid"]: x for x in add["펼침"]}
|
||||
assert sub["add:#0/labor:LB000036#0"]["덮개"] == ["qty"]
|
||||
assert sub["add:#0/labor:LB000036#0"]["수량"] == pytest.approx(0.072)
|
||||
assert add["뺀세부"] == [{"cid": "add:#0/" + DROP[0], "이름": "공구손료 및 경장비"}]
|
||||
lost = {**one, "덮개": {"labor:LB999999#0": {"qty": 1}}}
|
||||
got = _run(world["personal"], {**doc, "더한줄": [lost]})
|
||||
assert any(x["cid"] == "add:#0/labor:LB999999#0" for x in got["짝잃음"])
|
||||
|
||||
|
||||
def test_727_2_굳힘_같은_값(world, monkeypatch): # noqa: F811
|
||||
one = {**SECOND, "덮개": COVER, "뺀줄": DROP}
|
||||
key = _sk(
|
||||
world["personal"],
|
||||
바탕={"로직": GF},
|
||||
더한줄=[one],
|
||||
입력값={"보정작업": "암석작업(연암・보통암・경암)"},
|
||||
)
|
||||
ref = {**MINE, "키": key["키"]}
|
||||
with store.at(world["personal"]):
|
||||
top = labor.clean({"열": "rv", "담은로직": [{"참조": ref, "수량": {"손": 2}}]})
|
||||
live = labor.calc(top, {})["줄"][0]
|
||||
rows = source.labor_doc_rows(top)
|
||||
bundle = source.price_bundle(rows, world["personal"])
|
||||
frozen = rows["참조사본"][refs.ref_id(ref)]
|
||||
assert frozen["굳힌줄"]["호표"][-1]["값묶음"] # 고친 둘째 기초 = 셈한 값묶음 줄
|
||||
got = prices.calc(rows, json.loads(json.dumps(bundle, ensure_ascii=False)), {}, {}, None)
|
||||
line = got["줄"][0]
|
||||
assert not line["까닭"] and not live["까닭"]
|
||||
for part in ("노무비", "재료비", "경비", "계"):
|
||||
assert line["기준"][part] == pytest.approx(live["기준"][part], rel=1e-9)
|
||||
|
||||
|
||||
def test_727_3_옵션_저장_일위대가_그_옵션(world): # noqa: F811
|
||||
rock = {"지역": "전국평균", "보정작업": "암석작업(연암・보통암・경암)"}
|
||||
doc = _sk(
|
||||
@@ -191,14 +112,3 @@ def test_727_3_옵션_저장_일위대가_그_옵션(world): # noqa: F811
|
||||
up = refs.Expand(m01.loaded()[1])({**MINE, "키": doc["키"]})
|
||||
assert float(up["기준"]["계"]) == pytest.approx(_m01(GF, rock), rel=1e-9)
|
||||
assert _m01(GF, rock) > _m01(GF, {"지역": "전국평균", "보정작업": "해당 없음"})
|
||||
# 둘째 기초 입력(바탕에 없는 이름)도 SK 입력값에 남고 그 옵션으로 셈
|
||||
two = _sk( # 단위 = 바탕 단위(728-2 — 성격 다르면 계수 칸)
|
||||
world["personal"],
|
||||
바탕={"로직": PCT},
|
||||
단위="㎡",
|
||||
더한줄=[{**SECOND, "로직": GF}],
|
||||
입력값=rock,
|
||||
)
|
||||
assert two["입력값"] == rock
|
||||
got = _run(world["personal"], two)
|
||||
assert _line(got, "add:#0")["금액"] == pytest.approx(_m01(GF, rock), rel=1e-9)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""728-2 지킴 — SK 단위 환산: 바탕 기준단위 → SK 단위 배 · 화면 줄 · 계 = SK 1 단위 몫 ·
|
||||
계수 없으면 셈 막음 · 「식」 = 옛 셈 · 둘째 기초 수량 처음값 · 돈 아닌 기초 고르기 창에서 뺌 ·
|
||||
계수 없으면 셈 막음 · 「식」 = 옛 셈 · 돈 아닌 기초 고르기 창에서 뺌 ·
|
||||
고침 꼴 화면배 되돌림."""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -15,7 +15,6 @@ HERE = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "resources/master_data/scripts"))
|
||||
|
||||
import master_unit as mu # noqa: E402
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01 # noqa: E402
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as sc # noqa: E402
|
||||
@@ -38,10 +37,12 @@ def _shown(whole, doc):
|
||||
|
||||
def test_단목베기_100본_제안_본으로_바꾸면_1본_계(whole):
|
||||
full = _shown(whole, _doc("GF000287", "100본"))
|
||||
assert full["배"] == 1 and full["기준"]["계"] == Decimal("153889") # 751-3 1 원 버림
|
||||
assert full["배"] == 1 and full["기준"]["계"] == Decimal(
|
||||
"255186"
|
||||
) # 수식 문서 기본 옵션(흉고직경 14 · 단목 · 855 2-C1)
|
||||
assert sc.head_of({"단위": "100본"}) == "100본 당"
|
||||
one = _shown(whole, _doc("GF000287", "본"))
|
||||
assert one["배"] == 100 and round(one["기준"]["계"], 2) == Decimal("1538.89")
|
||||
assert one["배"] == 100 and round(one["기준"]["계"], 2) == Decimal("2551.86")
|
||||
assert sc.head_of({"단위": "본"}) == "1 본 당"
|
||||
pairs = [(x["수량"], y["수량"]) for x, y in zip(full["줄"], one["줄"], strict=True)]
|
||||
assert all(b == a / 100 for a, b in pairs) and one["화면배"] == 100 # 세부 품 ÷100
|
||||
@@ -71,25 +72,8 @@ def test_성격_다르면_계수_칸_없으면_셈_막음(whole):
|
||||
|
||||
def test_식_빈_단위는_옛_셈(whole):
|
||||
old = _shown(whole, _doc("GF000287", "식"))
|
||||
assert old["배"] == 100 and round(old["1단위"]["계"], 2) == Decimal("1538.89")
|
||||
assert "화면배" not in old and old["기준"]["계"] == Decimal("153889") # 화면 = 바탕 몫 그대로
|
||||
|
||||
|
||||
def test_둘째_기초_수량_처음값_배(whole):
|
||||
"""바탕 10㎡(GC000421) + 둘째 기초 100㎡(GF000041) — 처음값 0.1 = 바탕 기준단위 몫."""
|
||||
qty = mu.swap("10㎡", "100㎡")["배"]
|
||||
assert qty == Decimal("0.1")
|
||||
alone = sc.run(sd.clean(_doc("GF000041", "100㎡"), None, whole), whole)["1단위"]["계"]
|
||||
one = {"종류": "로직", "로직": "GF000041", "입력값": {}, "수량": float(qty)}
|
||||
got = sc.run(sd.clean(_doc("GC000421", "㎡", 더한줄=[one]), None, whole), whole)
|
||||
bare = sc.run(sd.clean(_doc("GC000421", "㎡"), None, whole), whole)
|
||||
added = got["1단위"]["계"] - bare["1단위"]["계"]
|
||||
# ㎡ 몫 = 100㎡ 값 ÷100 · 비목 합 1 원 버림(751-3)이라 바탕 몫 ÷10 = 0.1 원 안
|
||||
assert abs(added - alone * qty / 10) <= Decimal("0.1")
|
||||
src = (ROOT / "M02_MasterTemplete/M02_MasterTemplete_Sangeun_Detail.ts").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
assert "addBase(" not in src # 840-1 [항목 추가] 걷음
|
||||
assert old["배"] == 100 and round(old["1단위"]["계"], 2) == Decimal("2551.86")
|
||||
assert "화면배" not in old and old["기준"]["계"] == Decimal("255186") # 화면 = 바탕 몫 그대로
|
||||
|
||||
|
||||
def test_돈_아닌_기초_고르기_창에서_뺌(whole):
|
||||
|
||||
@@ -20,7 +20,6 @@ from fastapi.testclient import TestClient
|
||||
|
||||
from common_util.common_util_auth import verify_session
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Library_Flat as flat
|
||||
from M02_MasterTemplete import M02_Library_Same as same
|
||||
@@ -97,65 +96,6 @@ def _y(folder):
|
||||
)
|
||||
|
||||
|
||||
def test_SK_에_SK_몸_통째_금액_같음_원본_고쳐도_지워도_그대로(world):
|
||||
me = world["personal"]
|
||||
y = _y(me)
|
||||
legacy = {
|
||||
"이름": "밖",
|
||||
"단위": "㎥",
|
||||
"바탕": {"로직": GF},
|
||||
"더한줄": [{"참조": {**MINE, "키": y}, "수량": 2}],
|
||||
}
|
||||
before = _sk_total(me, {"키": "SK-000099", **legacy})
|
||||
x = _make(me, "sangeun", **legacy)
|
||||
doc = _read(me, "sangeun", x)
|
||||
entry = doc["더한줄"][0]
|
||||
assert not refs.refs_in(doc)
|
||||
assert entry["로직"] == PCT and entry["덮개"] and entry["더한줄"][0]["요소"] == "LB000002"
|
||||
assert entry["본뜬"]["키"] == y and entry["본뜬"]["이름"] == "원본" and entry["본뜬"]["때"]
|
||||
assert _sk_total(me, doc) == pytest.approx(before, rel=1e-9)
|
||||
with store.at(me): # 원본 고침 · 지움 → 넣은 쪽 그대로
|
||||
now = store.read("sangeun", y)
|
||||
store.write(
|
||||
"sangeun", y, now["판"], {**now["문서"], "덮개": {"labor:LB000002#0": {"qty": 2}}}
|
||||
)
|
||||
assert refs.users({**MINE, "키": y}) == []
|
||||
store.delete("sangeun", y)
|
||||
assert _sk_total(me, _read(me, "sangeun", x)) == pytest.approx(before, rel=1e-9)
|
||||
with store.at(me): # 화면 셈 길 = 넣은 줄 세부 펼침(안 더한줄 = add:#0/add:#0)
|
||||
got = calc.calc_doc(_read(me, "sangeun", x))
|
||||
sub = next(r for r in got["줄"] if r["cid"] == "add:#0")["펼침"]
|
||||
assert "add:#0/add:#0" in [r["cid"] for r in sub]
|
||||
|
||||
|
||||
def test_SC_에_SK_패치_겹침_E1_원본_고쳐도_그대로(world):
|
||||
"""분석 579-2 E1 — 밖 SC(SK 참조 + 줄 패치 · 안 SC) 의 원본 SK 다른 줄을 고쳐도 밖 금액
|
||||
그대로."""
|
||||
me = world["personal"]
|
||||
sk = _make(me, "sangeun", 이름="밑", 바탕={"로직": PCT}, 더한줄=[])
|
||||
inner = _make(me, "precombo", 이름="안", 담은로직=[{"로직": "GC001111"}])
|
||||
lines = [
|
||||
{"참조": {**MINE, "키": sk}, "패치": {"덮개": {"labor:LB000036#0": {"qty": 0.5}}}},
|
||||
{"참조": {**MINE, "키": inner}},
|
||||
]
|
||||
old = _raw(me, "precombo", 이름="옛 밖", 담은로직=lines)
|
||||
before = _sc_value(me, old)
|
||||
host = _make(me, "precombo", 이름="밖", 담은로직=lines)
|
||||
doc = _read(me, "precombo", host)
|
||||
assert doc["담은로직"][0]["참조"] == {**MINE, "키": sk} # 811-1 SK 줄 = 참조 한 행(안 펼침)
|
||||
assert doc["담은로직"][0]["패치"]["덮개"] == {"labor:LB000036#0": {"qty": 0.5}}
|
||||
assert doc["담은로직"][1]["참조"]["층"] == "사본" # 하위 호표(SC 안 SC) = 사본 블록
|
||||
assert doc["담은로직"][1]["본뜬"]["키"] == inner
|
||||
assert _sc_value(me, host) == pytest.approx(before, rel=1e-9)
|
||||
with store.at(me): # E1 — 원본 SK 의 덮지 않은 줄 품 2
|
||||
now = store.read("sangeun", sk)
|
||||
store.write(
|
||||
"sangeun", sk, now["판"], {**now["문서"], "덮개": {"labor:LB000002#0": {"qty": 2}}}
|
||||
)
|
||||
assert _sc_value(me, old) > before * 3 # 참조 = 따라감(129,073 → 481,406 꼴)
|
||||
assert _sc_value(me, host) == pytest.approx(_sc_value(me, old), rel=1e-9) # 811-1 = SK 따라감
|
||||
|
||||
|
||||
def test_SC_에_SC_사본_블록_실무수량_겹침_원본_지워도(world):
|
||||
"""하위 호표(SC 안 SC) = 사본 블록 — 원본 연결 없음 · 금액 같음 · 같은 기초 겹침도 블록 안."""
|
||||
me = world["personal"]
|
||||
@@ -180,108 +120,6 @@ def test_SC_에_SC_사본_블록_실무수량_겹침_원본_지워도(world):
|
||||
assert got["담은로직"][0]["참조"]["층"] == "사본" # 넣기 길도 블록(겹침 없음)
|
||||
|
||||
|
||||
def test_SK_에_SC_줄마다_더한줄(world):
|
||||
me = world["personal"]
|
||||
sc = _make(me, "precombo", 이름="조합", 담은로직=[{"로직": GF}])
|
||||
with store.at(me):
|
||||
got = flat.flat_lines("sangeun", {**MINE, "키": sc}, 2)["더한줄"]
|
||||
assert len(got) == 1 and got[0]["로직"] == GF and got[0]["수량"] == 2 # 실무수량 없음 = 1 × 2
|
||||
assert got[0]["본뜬"]["키"] == sc
|
||||
# 742-1 저장 수량(수량.손)이 있으면 그 수 · 안 SC 펴기 = 바깥 × 안
|
||||
from decimal import Decimal
|
||||
|
||||
hand = flat.sc_adds({"담은로직": [{"로직": GF, "수량": {"손": 3}}]}, Decimal(2), _whole(), {})
|
||||
assert hand[0]["수량"] == 6
|
||||
block = {"참조": refs.copy_ref({"담은로직": [{"로직": GF, "수량": {"손": 3}}]}, "SC-000001")}
|
||||
deep = flat.sc_adds({"담은로직": [{**block, "수량": {"손": 2}}]}, Decimal(1), _whole(), {})
|
||||
assert deep[0]["로직"] == GF and deep[0]["수량"] == 6 # 사본 블록 = 바깥 × 안
|
||||
doc = {"키": "SK-000099", "이름": "x", "단위": "㎥", "바탕": None, "더한줄": got}
|
||||
one = float(labor.run_line(_whole(), GF, {})["기준"]["계"])
|
||||
assert _sk_total(me, doc) == pytest.approx(2 * one, rel=1e-9)
|
||||
|
||||
|
||||
def test_바탕_SK_겹침_못_펼침_까닭(world):
|
||||
me = world["personal"]
|
||||
under = _make(
|
||||
me, "sangeun", 이름="밑", 바탕={"로직": PCT}, 덮개={"labor:LB000036#0": {"qty": 0.1}}
|
||||
)
|
||||
over = {"이름": "위", "단위": "㎡", "바탕": {"참조": {**MINE, "키": under}}, "더한줄": [ADD]}
|
||||
over |= {"덮개": {"labor:LB000036#0": {"배율": 2}}, "뺀줄": ["labor:LB000002#0"]}
|
||||
before = _sk_total(me, {"키": "SK-000099", **over})
|
||||
got = flat.flat_doc("sangeun", {"키": "SK-000099", **over})
|
||||
assert got["바탕"] == {"로직": PCT} and got["덮개"]["labor:LB000036#0"]["qty"] == 0.2
|
||||
assert got["뺀줄"] == ["labor:LB000002#0"]
|
||||
assert _sk_total(me, got) == pytest.approx(before, rel=1e-9)
|
||||
# SC 에 바탕 없는 SK · 단위 환산 SK = 못 넣음
|
||||
bare = _make(me, "sangeun", 이름="바탕 없음", 바탕=None, 더한줄=[ADD])
|
||||
with store.at(me):
|
||||
for key, why in ((bare, "바탕 기초 없는"),):
|
||||
with pytest.raises(store.StoreError) as e:
|
||||
flat.flat_lines("precombo", {**MINE, "키": key})
|
||||
assert e.value.status == 400 and why in str(e.value.detail)
|
||||
|
||||
|
||||
def test_초기화_SK_SC_M01_값_옵션_남음(world):
|
||||
me = world["personal"]
|
||||
rock = {"보정작업": "암석작업(연암・보통암・경암)"}
|
||||
entry = {
|
||||
"종류": "로직",
|
||||
"로직": PCT,
|
||||
"입력값": {},
|
||||
"수량": 1,
|
||||
"덮개": {"labor:LB000036#0": {"qty": 1}},
|
||||
}
|
||||
priced = {**ADD, "단가": 1}
|
||||
x = _make(
|
||||
me,
|
||||
"sangeun",
|
||||
이름="고친 것",
|
||||
단위="㎥",
|
||||
바탕={"로직": GF},
|
||||
입력값=rock,
|
||||
덮개={"labor:LB000002#0": {"qty": 1}},
|
||||
뺀줄=["logic:GC000267#0"],
|
||||
더한줄=[entry, priced],
|
||||
)
|
||||
with store.at(me):
|
||||
look = flat.reset_doc("sangeun", x, None, True, None)
|
||||
assert look["걷힘"] == 4 and _read(me, "sangeun", x)["덮개"] # 미리 보기 = 안 씀
|
||||
done = flat.reset_doc("sangeun", x, None, False, None)
|
||||
doc = _read(me, "sangeun", x)
|
||||
assert doc["덮개"] == {} and doc["뺀줄"] == [] and doc["입력값"] == rock
|
||||
assert [x.get("요소") or x.get("로직") for x in doc["더한줄"]] == [PCT, "LB000002"]
|
||||
assert "덮개" not in doc["더한줄"][0] and "단가" not in doc["더한줄"][1]
|
||||
assert done["걷힘"] == 4
|
||||
plain = {"키": "SK-000099", "이름": "x", "단위": "㎥", "바탕": {"로직": GF}, "입력값": rock}
|
||||
plain["더한줄"] = [{**entry, "덮개": {}}, ADD]
|
||||
assert _sk_total(me, doc) == pytest.approx(_sk_total(me, plain), rel=1e-9)
|
||||
sc = _make(
|
||||
me,
|
||||
"precombo",
|
||||
이름="줄 덮개",
|
||||
담은로직=[
|
||||
{"로직": PCT, "패치": {"덮개": {"labor:LB000036#0": {"qty": 1}}, "더한줄": [priced]}}
|
||||
],
|
||||
)
|
||||
with store.at(me):
|
||||
got = flat.reset_doc("precombo", sc, None, False, None)
|
||||
line = _read(me, "precombo", sc)["담은로직"][0]
|
||||
assert got["걷힘"] == 2 and line["패치"] == {"더한줄": [{**ADD, "수량": 0.5, "처음수량": 0.5}]}
|
||||
# 이음 기계 고정 줄(736-3) = M01 기계 한 시간 값 다시 받음
|
||||
from M02_MasterTemplete import M02_Machine_Hourly as machine
|
||||
|
||||
hour = machine.hourly("EQ000019")
|
||||
fx = {"이름": "굴착기", "단위": "시간", "단가": {"노무비": 1, "재료비": 1, "경비": 1}}
|
||||
fx["이음"] = {"기계": "EQ000019"}
|
||||
mc = _make(me, "precombo", 이름="기계", 담은로직=[{"고정": fx}])
|
||||
with store.at(me):
|
||||
assert flat.reset_doc("precombo", mc, None, False, None)["걷힘"] == 1
|
||||
price = _read(me, "precombo", mc)["담은로직"][0]["고정"]["단가"]
|
||||
assert price["노무비"] == pytest.approx(hour["노무비"]) and price["경비"] == pytest.approx(
|
||||
hour["경비"]
|
||||
)
|
||||
|
||||
|
||||
def test_길_넣기_초기화_권한(world):
|
||||
app = FastAPI()
|
||||
app.include_router(same_router.router)
|
||||
@@ -309,48 +147,3 @@ def test_733_지문_옛_참조_펼친_것_같음(world):
|
||||
assert refs.refs_in(_read(me, "precombo", new)) == [{**MINE, "키": y}] # 811-1 참조 한 행
|
||||
fingers = {k: same.finger("precombo", _read(me, "precombo", k)) for k in (old, new)}
|
||||
assert fingers[old] == fingers[new]
|
||||
|
||||
|
||||
def test_B09_SC_덮개_줄_대가_금액_M02_같음(world, tmp_path):
|
||||
"""SC 덮개 줄(SK 넣기 꼴) — 옛 B09 = 산근(덮개 안 읽음) · 이제 굳힌 줄 대가 = M02 값."""
|
||||
from B09_Estimation import B09_Estimation_Bill_Library as library
|
||||
from resources.tester.test_719_2_sk_project import _b09, _project
|
||||
|
||||
me = world["personal"]
|
||||
cover = {"labor:LB000036#0": {"qty": 0.5}}
|
||||
sc = _make(
|
||||
me,
|
||||
"precombo",
|
||||
이름="덮은 줄",
|
||||
담은로직=[{"로직": PCT, "패치": {"덮개": cover, "더한줄": [ADD]}}],
|
||||
)
|
||||
m02 = _sc_value(me, sc)
|
||||
bare = float(labor.run_line(_whole(), PCT, {})["기준"]["계"])
|
||||
assert m02 > bare * 2 # 덮개 · 더한줄이 값에 듦(옛 B09 산근 = bare)
|
||||
root = _project(tmp_path / "proj", [])
|
||||
made = library.import_copy(root, "precombo", "personal", "7/42", sc)
|
||||
daega, done, _ = _b09(root)
|
||||
block = done[daega["libs"][made["폴더"]]]
|
||||
line = block["lines"][0]
|
||||
assert line["kind"] == "daega" and block["blank"] == 1 # 안 줄 수량 = 이 공사에서 입력(723-4)
|
||||
cover_qty = {block["cover"]: {line["cid"]: {"qty": 1}}}
|
||||
block = _b09(root, cover_qty)[1][daega["libs"][made["폴더"]]]
|
||||
assert block["blank"] == 0
|
||||
assert block["sum"] == pytest.approx(m02, abs=5) # 끝수(내림)만 다름
|
||||
|
||||
|
||||
def test_747_SK_재료_직접계산_일위대가에_넣어도_같은_금액(world):
|
||||
"""747-1 SK 바탕 재료 = 직접계산 · 일위대가 줄 기본 = 별도계상 → 펼친 줄에 적어 둠."""
|
||||
me = world["personal"]
|
||||
form = "GC000211" # 합판거푸집 — 재료 줄 있음
|
||||
plain = _make(me, "sangeun", 이름="거푸집", 바탕={"로직": form})
|
||||
cover = {"material:합판(내수 12㎜)#0": {"qty": 2}}
|
||||
covered = _make(me, "sangeun", 이름="거푸집 고침", 바탕={"로직": form}, 덮개=cover)
|
||||
for sk in (plain, covered):
|
||||
lines = [{"참조": {**MINE, "키": sk}}]
|
||||
old = _raw(me, "precombo", 이름="옛", 담은로직=lines)
|
||||
before = _sc_value(me, old)
|
||||
host = _make(me, "precombo", 이름="새", 담은로직=lines)
|
||||
line = _read(me, "precombo", host)["담은로직"][0]
|
||||
assert line["참조"]["키"] == sk # 811-1 참조 한 행 = SK 재료 직접계산 그대로
|
||||
assert _sc_value(me, host) == pytest.approx(before, rel=1e-9)
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
"""
|
||||
|
||||
import os
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -109,22 +108,6 @@ def test_B09_옛_사본_null_은_그대로_빈_줄():
|
||||
assert compute_labor(daega, SHEETS)["daega_blocks"][0]["blank"] == 3
|
||||
|
||||
|
||||
def test_단가산출_안_일위대가_저장_수량_금액(world): # noqa: F811
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
|
||||
key = _sc(world, [{"로직": STONE, "수량": {"손": 2}}])
|
||||
sk = {
|
||||
"키": "SK-000001",
|
||||
"이름": "겹",
|
||||
"단위": "식",
|
||||
"더한줄": [{"참조": {**SYS, "키": key}, "수량": 3}],
|
||||
}
|
||||
with store.at(world["system"]):
|
||||
got = calc.calc_doc(calc.clean_doc(sk, refs.here()))
|
||||
assert not got["빠진줄"]
|
||||
assert got["1단위"]["계"] == pytest.approx(float(Decimal(str(_stone())) * 2 * 3), rel=1e-6)
|
||||
|
||||
|
||||
def _src(name: str) -> str:
|
||||
return open(os.path.join(SRC, name), encoding="utf-8").read()
|
||||
|
||||
@@ -133,7 +116,9 @@ def test_화면_수량_칸_저장_새_줄_1_두_칸():
|
||||
table = _src("M02_MasterTemplete_Labor_Table.ts")
|
||||
assert "const temp = new Map" not in table and "withTemp" not in table # 휘발 칸 걷음
|
||||
assert "row.수량 = raw ? { 손: v } : null;" in table and "changed(true);" in table
|
||||
assert table.count("수량: fresh()") == 4 # 기초 · 참조 · 고정 · 자재 새 줄 = 서고 1 · 조합 면적 따름(806-1)
|
||||
assert (
|
||||
table.count("수량: fresh()") == 4
|
||||
) # 기초 · 참조 · 고정 · 자재 새 줄 = 서고 1 · 조합 면적 따름(806-1)
|
||||
assert "const fresh = (): LaborRow" in table and "{ ...ONE }" in table
|
||||
assert 'BasePrice: ["기준단위 단가"' in table and 'QtyAmount: ["수량 반영 금액"' in table
|
||||
assert 'sum_price: t("BasePrice"), sum: t("QtyAmount")' in table
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
# ruff: noqa: F811 — 임시 층 fixture(world)를 test_m02_labor_ref 에서 받아 씀
|
||||
"""744-1 서버 — 둘째 기초 세부 품 원문 · 되돌리기 기억(임시 storage · M01 읽기만).
|
||||
|
||||
- 둘째 기초 `펼침` 줄 `원문` = 그 기초 1 기준단위 몫(GF000316 품 그대로) · 줄 수량 · 금액 = 머리
|
||||
수량 곱한 몫(상자 합) 그대로 · 머리 수량 = 더한줄 수량
|
||||
- 더한줄 `처음수량` = 넣을 때 수량(없으면 저장 때 지금 수량) · 셈 · 지문 안 듦
|
||||
- `뺀더한줄 [{차례, 줄}]` = [기초 빼기] · 더한 항목 빼기 기억 · 셈 · 지문 안 듦 · 못 읽는 줄 버림 ·
|
||||
일위대가 줄 패치도 같음
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Library_Same as same
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from resources.tester.test_m02_labor_ref import world # noqa: F401
|
||||
|
||||
GF = "GF000099" # 원/㎥
|
||||
BIG = "GF000316" # 기준단위 100㎥ — ㎥ 바탕에서 처음 수량 0.01
|
||||
PCT = "GC001109"
|
||||
MAN = {"종류": "인력", "요소": "LB000002", "수량": 1}
|
||||
|
||||
|
||||
def _sk(folder, **doc):
|
||||
with store.at(folder):
|
||||
made = refs.create("sangeun", {"이름": "744", "단위": "㎥", "더한줄": [], **doc})
|
||||
return store.read("sangeun", made["이름"])["문서"]
|
||||
|
||||
|
||||
def _calc(folder, doc):
|
||||
with store.at(folder):
|
||||
return calc.calc_doc(doc)
|
||||
|
||||
|
||||
def test_둘째_기초_세부_원문_품_머리_수량(world):
|
||||
doc = _sk(
|
||||
world["personal"], 바탕={"로직": GF}, 더한줄=[{"종류": "로직", "로직": BIG, "수량": 0.01}]
|
||||
)
|
||||
got = _calc(world["personal"], doc)
|
||||
head = next(x for x in got["줄"] if x["cid"] == "add:#0")
|
||||
m01_lines = labor.run_line(m01.loaded()[1], BIG, {})["줄"]
|
||||
assert head["수량"] == pytest.approx(0.01)
|
||||
for row, line in zip(head["펼침"], m01_lines):
|
||||
assert row["원문"]["수량"] == pytest.approx(float(line["수량"]), rel=1e-9) # 원문 그대로
|
||||
assert row["수량"] == pytest.approx(float(line["수량"]) * 0.01, rel=1e-9) # 상자 몫
|
||||
# 머리 = 수량 × 기초 끝수 계(751-3 · 비목 1 원 · 줄 0.1 원 버림) — 펼침 합과 0.3 + 수량 × 3 원 안
|
||||
near = 0.3 + 3 * 0.01
|
||||
assert sum(x["금액"] for x in head["펼침"]) == pytest.approx(head["금액"], abs=near)
|
||||
assert sum(x["원문"]["금액"] for x in head["펼침"]) * 0.01 == pytest.approx(
|
||||
head["금액"], abs=near
|
||||
)
|
||||
|
||||
|
||||
def test_처음수량_넣을때_값_셈_지문_안_듦(world):
|
||||
me = world["personal"]
|
||||
plain = _sk(me, 바탕={"로직": PCT}, 단위="㎡", 더한줄=[{**MAN, "수량": 3}])
|
||||
assert plain["더한줄"][0]["처음수량"] == 3 # 없으면 저장 때 지금 수량
|
||||
kept = _sk(me, 바탕={"로직": PCT}, 단위="㎡", 더한줄=[{**MAN, "수량": 3, "처음수량": 1}])
|
||||
assert kept["더한줄"][0]["처음수량"] == 1
|
||||
assert _calc(me, kept)["기준"]["계"] == _calc(me, plain)["기준"]["계"]
|
||||
assert same.finger("sangeun", kept) == same.finger("sangeun", plain)
|
||||
|
||||
|
||||
def test_뺀더한줄_기억_셈_지문_안_듦_못읽는_줄_버림(world):
|
||||
me = world["personal"]
|
||||
gone = [
|
||||
{"차례": 0, "줄": {"종류": "로직", "로직": BIG, "수량": 0.01, "덮개": {}}},
|
||||
{"차례": 1, "줄": MAN},
|
||||
{"차례": -1, "줄": MAN}, # 차례 틀림
|
||||
{"차례": 2, "줄": {"종류": "로직", "로직": "GX999999", "수량": 1}}, # 없는 기초
|
||||
{"차례": 3}, # 줄 없음
|
||||
]
|
||||
doc = _sk(me, 바탕={"로직": GF}, 뺀더한줄=gone)
|
||||
assert [x["차례"] for x in doc["뺀더한줄"]] == [0, 1]
|
||||
assert doc["뺀더한줄"][1]["줄"]["요소"] == "LB000002"
|
||||
bare = _sk(me, 바탕={"로직": GF})
|
||||
assert _calc(me, doc)["기준"]["계"] == _calc(me, bare)["기준"]["계"]
|
||||
assert same.finger("sangeun", doc) == same.finger("sangeun", bare)
|
||||
|
||||
|
||||
def test_일위대가_줄_패치_기억_처음수량(world):
|
||||
me = world["personal"]
|
||||
patch = {"더한줄": [{**MAN, "수량": 2}], "뺀더한줄": [{"차례": 0, "줄": MAN}]}
|
||||
with store.at(me):
|
||||
sc = refs.create(
|
||||
"precombo", {"이름": "744", "단위": "㎡", "담은로직": [{"로직": PCT, "패치": patch}]}
|
||||
)
|
||||
line = store.read("precombo", sc["이름"])["문서"]["담은로직"][0]
|
||||
assert line["패치"]["더한줄"][0]["처음수량"] == 2
|
||||
assert line["패치"]["뺀더한줄"][0]["줄"]["요소"] == "LB000002"
|
||||
@@ -28,18 +28,17 @@ def test_base_materials_count_like_m01():
|
||||
got = _run(바탕={"로직": FORM})
|
||||
assert got["기준"]["재료비"] == pytest.approx(m01_["기준"]["재료비"])
|
||||
assert got["기준"]["계"] == pytest.approx(m01_["기준"]["계"])
|
||||
qty = {x["cid"]: x["수량"] for x in got["줄"]}
|
||||
assert qty[PLY] == pytest.approx(1.03)
|
||||
assert qty["material:폼타이 12.7㎜#0"] == 0 # M01 수량 0 = 0 그대로
|
||||
qty = {x["이름"]: x["수량"] for x in got["줄"]} # 줄 = 수식 문서 금액 줄(855 2-C1)
|
||||
assert qty["합판(내수 12㎜)"] == pytest.approx(1.03)
|
||||
assert qty["폼타이 12.7㎜"] == 0 # M01 수량 0 = 0 그대로
|
||||
|
||||
|
||||
def test_cover_and_explicit_apart():
|
||||
def test_explicit_apart():
|
||||
"""「별도계상」 고른 재료 줄만 계 밖(문서 금액 줄 `합밖`) — 옛 칸 덮개는 셈 은퇴(855 2-C1)."""
|
||||
base = _run(바탕={"로직": FORM})
|
||||
more = _run(바탕={"로직": FORM}, 덮개={PLY: {"qty": 2}})
|
||||
ply = next(x for x in base["줄"] if x["cid"] == PLY)
|
||||
assert more["기준"]["재료비"] > base["기준"]["재료비"] + ply["단가"] * 0.9
|
||||
ply = next(x for x in base["줄"] if x["이름"] == "합판(내수 12㎜)")
|
||||
out = _run(바탕={"로직": FORM}, 자재표시={PLY: {"별도계상": "별도계상"}})
|
||||
assert all(x["cid"] != PLY for x in out["줄"])
|
||||
assert next(x for x in out["줄"] if x["이름"] == "합판(내수 12㎜)")["합밖"] is True
|
||||
assert out["기준"]["재료비"] < base["기준"]["재료비"] - ply["금액"] + 1
|
||||
|
||||
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
"""SK 보기 넷 = 셈 답 하나(PLAN 750-1 · 요구 588-1) — 화면 셈 답 `글`(텍스트 수식) ·
|
||||
시험 계산(`줄` · `기준` · `중간`) = SK 줄 · 계 · 변형 일곱(기본 · 줄 빼기 · 더하기 · 덧줄 ·
|
||||
별도계상 · 단위 환산 · 재료 고름) + 참조 바탕 · 일위대가 줄 모달(`줄모드`) = 일위대가 그 줄 셈 ·
|
||||
`보기` false = 덧칸 없음 · M01 엔진 · storage 안 씀."""
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from M02_MasterTemplete import M02_Sangeun_Doc as sd
|
||||
from M02_MasterTemplete import M02_Sangeun_Views as views
|
||||
|
||||
FORM = "GC000211" # 6-3-1 합판거푸집 — 재료 일곱 · 소모자재 = 재료비 % 덧줄
|
||||
PLY = "material:합판(내수 12㎜)#0"
|
||||
DOC = {"키": "SK-000002", "이름": "테스트1", "단위": "㎡", "바탕": {"로직": FORM}}
|
||||
ADD = {"종류": "인력", "요소": "LB000002", "이름": "보통인부(더함)", "단위": "인", "수량": 0.05}
|
||||
CASES = {
|
||||
"기본": {},
|
||||
"줄 빼기": {"뺀줄": ["material:각재#0"]},
|
||||
"더하기": {"더한줄": [ADD]},
|
||||
"덧줄": {"덮개": {"pct:소모자재#0": {"qty": 5}}},
|
||||
"별도계상": {"자재표시": {PLY: {"별도계상": "별도계상"}}},
|
||||
"단위 환산": {"단위": "10㎡"},
|
||||
"재료 고름": {"고름": {PLY: "MT000037"}}, # 830-2 — 지역 줄(부산) 통합 · 다른 품목 줄을 고름
|
||||
}
|
||||
|
||||
|
||||
def _whole():
|
||||
return m01.loaded()[1]
|
||||
|
||||
|
||||
def _answer(doc: dict, read=None, line: bool = False) -> dict:
|
||||
"""`calc_doc` 와 같은 길(층 검사만 뺌)."""
|
||||
whole = _whole()
|
||||
clean = sd.clean(doc, None, whole)
|
||||
got = calc.run(clean, whole, None, read or calc.refs.read_ref, detail=True, line=line)
|
||||
return labor._json(views.finish(calc.per_unit(got, clean)))
|
||||
|
||||
|
||||
def _same(a: dict) -> None:
|
||||
text, base = a["글"], a["기준"]
|
||||
assert text["ok"] is True
|
||||
money: dict[str, float] = {}
|
||||
for g in text["groups"]:
|
||||
assert g["소계"] == pytest.approx(base[g["비목"]])
|
||||
for one in g["줄"]:
|
||||
money[one["cid"]] = money.get(one["cid"], 0) + (one["금액"] or 0)
|
||||
assert set(money) == {x["cid"] for x in a["줄"]} # 글 줄 = SK 줄(cid)
|
||||
for x in a["줄"]:
|
||||
assert money[x["cid"]] == pytest.approx(x["금액"] or 0)
|
||||
assert text["계"] == pytest.approx(base["계"])
|
||||
# 시험 계산 표 합 — 줄 0.1 원 · 비목 합 1 원 버림(751-3) = 줄 합 아래 비목마다 1 원(× 화면 배) 안
|
||||
gap = sum(x["금액"] or 0 for x in a["줄"]) - base["계"]
|
||||
assert -1e-6 <= gap < 3 / (a.get("화면배") or 1)
|
||||
assert a["중간"] and all(not isinstance(v, (dict, list)) for v in a["중간"].values())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", list(CASES))
|
||||
def test_four_views_one_answer(name):
|
||||
a = _answer({**DOC, **CASES[name]})
|
||||
_same(a)
|
||||
if name == "별도계상":
|
||||
assert all(one.get("cid") != PLY for g in a["글"]["groups"] for one in g["줄"])
|
||||
if name == "단위 환산":
|
||||
assert a["글"]["나눔"] == pytest.approx(0.1)
|
||||
plain = _answer(DOC)
|
||||
assert a["기준"]["계"] == pytest.approx(plain["기준"]["계"] * 10)
|
||||
if name == "재료 고름":
|
||||
assert a["기준"]["재료비"] != pytest.approx(_answer(DOC)["기준"]["재료비"])
|
||||
|
||||
|
||||
def test_ref_base_same():
|
||||
"""참조 바탕(SK 위 SK) — 글도 바탕 SK 고친 줄 위에서."""
|
||||
parent = {**DOC, **CASES["덧줄"], "뺀줄": ["material:각재#0"]}
|
||||
ref = {"층": "personal", "주인": None, "키": "SK-000002"}
|
||||
_same(_answer({**DOC, "키": "SK-000003", "바탕": {"참조": ref}}, read=lambda r: parent))
|
||||
|
||||
|
||||
def test_row_modal_is_hopyo_line():
|
||||
"""일위대가 줄 모달(`줄모드`) = 일위대가 그 줄 셈(별도계상 기본 · 747 한쪽 흠)."""
|
||||
whole = _whole()
|
||||
line = labor._json(labor.drop_apart(labor.run_line(whole, FORM, None), {}))
|
||||
got = _answer({**DOC, "단위": "식", "줄모드": True}, line=True)
|
||||
assert got["기준"]["계"] == pytest.approx(line["기준"]["계"])
|
||||
assert [x["이름"] for x in got["줄"]] == [x["이름"] for x in line["줄"]]
|
||||
_same(got)
|
||||
|
||||
|
||||
def test_no_views_flag():
|
||||
"""`보기` false(바탕 원값 셈) = 금액만 · 덧칸 없음 · 금액 같음."""
|
||||
whole = _whole()
|
||||
clean = sd.clean(DOC, None, whole)
|
||||
got = labor._json(calc.run(clean, whole, None, detail=True, seen=False))
|
||||
assert "글" not in got and "중간" not in got
|
||||
assert got["기준"]["계"] == pytest.approx(_answer(DOC)["기준"]["계"])
|
||||
@@ -16,10 +16,6 @@ import master_sheet_line as msl # noqa: E402
|
||||
import master_text as mtx # noqa: E402
|
||||
import pytest # noqa: E402
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01 # noqa: E402
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor # noqa: E402
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc # noqa: E402
|
||||
from M02_MasterTemplete import M02_Sangeun_Doc as sd # noqa: E402
|
||||
|
||||
FORM = "GC000211" # 6-3-1 합판거푸집 — 폼타이 12.7 · 9.5 · 7.9 규격마다 줄
|
||||
TIES = ("폼타이 12.7㎜", "폼타이 9.5㎜", "폼타이 7.9㎜")
|
||||
@@ -95,14 +91,3 @@ def test_sheet_text_carries_mark(master):
|
||||
assert lines["폼타이 9.5㎜"].get(mg.KEY) is None
|
||||
assert lines["폼타이 12.7㎜"][mg.KEY] is True and lines["폼타이 7.9㎜"][mg.KEY] is True
|
||||
assert mg.KEY in msl.KEYS # M02 `/logic-lib/sheet` 도 같은 칸
|
||||
|
||||
|
||||
def test_sk_calc_carries_mark():
|
||||
whole = m01.loaded()[1]
|
||||
doc = {"키": "SK-000001", "이름": "시험", "단위": "㎡", "바탕": {"로직": FORM}}
|
||||
clean = sd.clean(doc, None, whole)
|
||||
got = labor._json(calc.run(clean, whole, {"폼타이": "사용", "폼타이규격": "12.7㎜"}))
|
||||
marked = {x["cid"] for x in got["줄"] if x.get(mg.KEY)}
|
||||
assert marked == {"material:폼타이 9.5㎜#0", "material:폼타이 7.9㎜#0"}
|
||||
base = labor._json(calc.run(clean, whole))
|
||||
assert base["기준"]["계"] == pytest.approx(got["기준"]["계"])
|
||||
|
||||
@@ -15,10 +15,13 @@ from resources.tester.test_m02_hopyo_excel import client # noqa: F401
|
||||
def test_목록_밖_기계_서버_둘째_요청에도_셈(client): # noqa: F811
|
||||
m01.loaded() # 마스터 = 이 스레드에서 지음 · 요청 = 다른 스레드(문맥 안 따라감)
|
||||
client.app.include_router(sangeun_router.router)
|
||||
one = {"종류": "로직", "로직": "GC000268", "입력값": {units.MACH_IN: "0211-0060"},
|
||||
"이름": "굴착기(타이어) 0.6㎥", "단위": "시간", "수량": 1} # fmt: skip
|
||||
doc = {"키": "SK-000000", "이름": "t", "단위": "시간", "바탕": None, "입력값": {}, "덮개": {},
|
||||
"뺀줄": [], "자재표시": {}, "더한줄": [one]} # fmt: skip
|
||||
doc = {
|
||||
"키": "SK-000000",
|
||||
"이름": "t",
|
||||
"단위": "시간",
|
||||
"바탕": {"로직": "GC000268"},
|
||||
"입력값": {units.MACH_IN: "0211-0060"},
|
||||
} # fmt: skip — 855 2-C1 바탕 로직 + 입력값
|
||||
for _ in range(2):
|
||||
got = client.post("/api/m02/layers/personal/sangeun/calc", json={"문서": doc})
|
||||
assert got.status_code == 200, got.text
|
||||
|
||||
@@ -68,71 +68,6 @@ LABOR = [
|
||||
|
||||
|
||||
# ── 서버 셈 ──────────────────────────────────────────────────────────────────
|
||||
def test_묶음_인력은_인력_줄만_노무비와_다름():
|
||||
got = _run(_doc([*LABOR, _rate("인력"), _rate("노무비", 3, name="노무 율")]))
|
||||
by = {x["cid"]: x for x in got["줄"]}
|
||||
people = sum(Decimal(str(by[f"add:#{k}"]["금액"])) for k in (0, 1))
|
||||
mach = Decimal(str(by["add:#2"]["비목"]["노무비"]))
|
||||
assert mach > 0 # 기계 노무 섞인 블록
|
||||
tool, cost = by["add:#3"], by["add:#4"]
|
||||
assert tool["금액"] == pytest.approx(float(people * 2 / 100), abs=0.1)
|
||||
assert cost["금액"] == pytest.approx(float((people + mach) * 3 / 100), abs=0.1)
|
||||
assert tool["율"] == 2 and tool["규격"] == "인력의 %" and tool["묶음"] == "경비"
|
||||
assert tool["비목"]["경비"] == pytest.approx(tool["금액"])
|
||||
assert got["짝잃음"] == []
|
||||
|
||||
|
||||
def test_줄_목록_절_소계와_율_위_율():
|
||||
adds = [*LABOR, _rate("인력"), _rate(["add:#0", "add:#3"], 10, "재료비", "율 위 율")]
|
||||
adds.append(_rate(["add:#0", "add:#1"], 5, name="절 소계"))
|
||||
got = _run(_doc(adds))
|
||||
by = {x["cid"]: x for x in got["줄"]}
|
||||
first = Decimal(str(by["add:#0"]["금액"]))
|
||||
tool = (first + Decimal(str(by["add:#1"]["금액"]))) * 2 / 100
|
||||
assert by["add:#4"]["금액"] == pytest.approx(float((first + tool) * 10 / 100), abs=0.1)
|
||||
assert by["add:#4"]["비목"]["재료비"] == pytest.approx(by["add:#4"]["금액"])
|
||||
part = first + Decimal(str(by["add:#1"]["금액"]))
|
||||
assert by["add:#5"]["금액"] == pytest.approx(float(part * 5 / 100), abs=0.1)
|
||||
|
||||
|
||||
def test_줄_목록_비목_몫_절_노무비():
|
||||
adds = [*LABOR, _rate(["add:#0", "add:#2@노무비"], 6, name="제잡비")]
|
||||
by = {x["cid"]: x for x in _run(_doc(adds))["줄"]}
|
||||
want = Decimal(str(by["add:#0"]["금액"])) + Decimal(str(by["add:#2"]["비목"]["노무비"]))
|
||||
assert by["add:#3"]["금액"] == pytest.approx(float(want * 6 / 100), abs=0.1)
|
||||
with pytest.raises(sd.DocError, match="자기"):
|
||||
sd.clean(_doc([LABOR[0], _rate(["add:#1@노무비"])]), None, _whole())
|
||||
|
||||
|
||||
def test_바탕_SK_율_줄과_바탕_덧줄():
|
||||
whole = _whole()
|
||||
doc = {**_doc([_rate("인력", 2)]), "바탕": {"로직": SUB}, "단위": "주"}
|
||||
got = labor._json(calc.run(sd.clean(doc, None, whole), whole))
|
||||
bare = labor.run_line(whole, SUB, {})
|
||||
people = sum(Decimal(str(bare["줄"][k]["금액"])) for k in (0, 1))
|
||||
rate = next(x for x in got["줄"] if x["cid"] == "add:#0")
|
||||
assert rate["금액"] == pytest.approx(float(people * 2 / 100), abs=0.1)
|
||||
assert got["기준"]["경비"] == pytest.approx(
|
||||
float(Decimal(str(bare["기준"]["경비"])) + Decimal(str(rate["금액"]))), abs=1
|
||||
)
|
||||
|
||||
|
||||
def test_없는_기준_줄_짝잃음():
|
||||
got = _run(_doc([LABOR[0], _rate(["add:#0", "labor:LB000099#0"])]))
|
||||
assert got["짝잃음"] == [{"cid": "add:#1", "까닭": "율 기준 줄 없음 「labor:LB000099#0」"}]
|
||||
got = _run(_doc([LABOR[0], _rate([])])) # 기준 줄을 지운 뒤 = 밑 0 · 알림
|
||||
assert got["짝잃음"] == [{"cid": "add:#1", "까닭": "율 기준 줄 없음 「」"}]
|
||||
assert got["줄"][1]["금액"] == 0
|
||||
|
||||
|
||||
def test_율_줄_없으면_엔진_한_번(monkeypatch):
|
||||
calls = []
|
||||
real = labor.run_line
|
||||
monkeypatch.setattr(labor, "run_line", lambda *a, **k: calls.append(1) or real(*a, **k))
|
||||
_run(_doc(LABOR))
|
||||
assert len(calls) == 1
|
||||
_run(_doc([*LABOR, _rate("인력")]))
|
||||
assert len(calls) == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -18,7 +18,6 @@ import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Library_Flat as flat
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from M02_MasterTemplete import M02_Sangeun_Const as const
|
||||
@@ -87,30 +86,6 @@ def test_scan_엔진_차례():
|
||||
|
||||
|
||||
# ── 금액 = 견본(서버 셈) ──────────────────────────────────────────────
|
||||
def test_상수_표값_덮개_견본_금액():
|
||||
roof = {**F211, "지붕슬래브": ROOF}
|
||||
assert _sum(_doc(FORM, F211)) == 51419
|
||||
assert _sum(_doc(FORM, roof)) == 59341
|
||||
assert _sum(_doc(FORM, roof, 상수덮개={"mid:시공량": {"2": 20}})) == 61088
|
||||
assert _sum(_doc(FORM, F211, 상수덮개={TOOL: {"0": 2}})) == 51802
|
||||
assert _sum(_doc(CARRY, _carry())) == 42917
|
||||
assert _sum(_doc(CARRY, _carry(), 상수덮개={"mid:일운반회수": {"1": 100}})) == 38696
|
||||
assert _sum(_doc(CARRY, _carry(), 표값덮개={"mid:운반량": {"0": 30}})) == 35764
|
||||
|
||||
|
||||
def test_옵션_바꿔도_상수_덮개_따라감():
|
||||
"""품 덮개(숫자로 굳힘)와 달리 식 구조 그대로 — 유형 복잡 = 손으로 식 고친 줄과 같은 값."""
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
|
||||
whole = _whole()
|
||||
given = {**F211, "지붕슬래브": ROOF, "유형": "복잡"}
|
||||
got = _sum(_doc(FORM, given, 상수덮개={"mid:시공량": {"2": 20}}))
|
||||
row = json.loads(json.dumps(whole.logic(FORM), ensure_ascii=False, default=str))
|
||||
for s in row["중간"]:
|
||||
if s["이름"] == "시공량":
|
||||
s["식"] = s["식"].replace(", 0, 17))", ", 0, 20))")
|
||||
hand = labor.run_line(calc._Over(whole, FORM, row), FORM, given)["기준"]["계"]
|
||||
assert got == float(hand) and got not in (61088, _sum(_doc(FORM, given)))
|
||||
|
||||
|
||||
# ── 문서 꼴 ──────────────────────────────────────────────────────────
|
||||
@@ -168,67 +143,8 @@ def _calc(folder, doc, given=None):
|
||||
return calc.calc_doc(doc, given)
|
||||
|
||||
|
||||
def test_저장_M01판_셈답_원래_시트(world):
|
||||
mine = world["personal"]
|
||||
key = _sk(
|
||||
mine,
|
||||
바탕={"로직": FORM},
|
||||
입력값={**F211, "지붕슬래브": ROOF},
|
||||
상수덮개={"mid:시공량": {"2": 20}},
|
||||
덮개={"labor:LB000002#0": {"qty": 0.05}},
|
||||
글줄=[{"자리": "", "글": "※ 지붕 경사 반영"}],
|
||||
까닭={"mid:시공량": "감률 20 % 적용"},
|
||||
)
|
||||
doc = _read(mine, key)
|
||||
assert doc["상수덮개"] == {"mid:시공량": {"2": 20}} and len(doc["바탕판"]) == 16
|
||||
assert set(doc["M01판"]) >= {"mid:시공량", TOOL, "labor:LB000007#0"}
|
||||
got = _calc(mine, doc)
|
||||
assert got["원래"]["계"] == 59341 # 같은 옵션 · 덮개 없음
|
||||
assert got["기준"]["계"] != 59341
|
||||
no_qty = _calc(mine, {**doc, "덮개": {}})
|
||||
assert no_qty["기준"]["계"] == 61088 and no_qty["원래"]["계"] == 59341
|
||||
spot = got["시트"]["자리"]["mid:시공량"]
|
||||
assert spot["갈래"] == "중간" and spot["덮개"] == ["상수"] and spot["까닭"] == "감률 20 % 적용"
|
||||
assert spot["상수"][2] == {"n": 2, "값": 20, "원값": 17}
|
||||
assert spot["표값"][0]["글"].startswith("찾기(QC000431") and spot["표값"][0]["값"] == 45
|
||||
assert spot["원래"] > spot["지금"] and spot["M01바뀜"] is False
|
||||
line = got["시트"]["자리"]["labor:LB000002#0"]
|
||||
assert line["덮개"] == ["품"] and line["원래"] != line["지금"]
|
||||
assert got["시트"]["글줄"] == [{"자리": "", "글": "※ 지붕 경사 반영"}]
|
||||
assert got["시트"]["짝잃음"] == []
|
||||
# M01 바뀜 — 저장 지문과 지금 바탕이 다른 자리만 · 사라진 자리 = 짝잃음
|
||||
stale = {**doc, "M01판": {**doc["M01판"], "mid:시공량": "000000000000", "mid:없는줄": "1"}}
|
||||
got = _calc(mine, stale)
|
||||
flags = {s for s, x in got["시트"]["자리"].items() if x.get("M01바뀜")}
|
||||
assert flags == {"mid:시공량"}
|
||||
assert {"cid": "mid:없는줄", "까닭": "M01 바뀜 — 바탕에 없는 줄"} in got["시트"]["짝잃음"]
|
||||
|
||||
|
||||
def test_짝잃은_새_덮개_알림(world):
|
||||
doc = _doc(FORM, F211, 상수덮개={"mid:없음": {"0": 1}, "mid:시공량": {"9": 1}})
|
||||
got = _calc(world["personal"], doc)
|
||||
assert got["기준"]["계"] == 51419
|
||||
why = {(x["cid"], x["까닭"]) for x in got["시트"]["짝잃음"]}
|
||||
assert why == {
|
||||
("mid:없음", "상수덮개 — 바탕에 없는 줄"),
|
||||
("mid:시공량", "상수덮개 — 10 번째 없음"),
|
||||
}
|
||||
|
||||
|
||||
def test_옛_저장본_셈답(world):
|
||||
"""새 칸 없는 옛 저장본(M01판 없음) = 금액 그대로 · M01바뀜 없음."""
|
||||
got = _calc(world["personal"], {**_doc(FORM, F211), "바탕판": "0" * 16})
|
||||
assert got["기준"]["계"] == 51419 == got["원래"]["계"]
|
||||
assert not any(x.get("M01바뀜") for x in got["시트"]["자리"].values())
|
||||
|
||||
|
||||
def test_펼침_막음_초기화_걷음(world):
|
||||
mine = world["personal"]
|
||||
a = _sk(mine, 바탕={"로직": CARRY}, 입력값=_carry(), 상수덮개={"mid:일운반회수": {"1": 100}})
|
||||
b = _sk(mine, 바탕=None, 더한줄=[{"참조": {**MINE, "키": a}, "수량": 1}])
|
||||
assert _read(mine, b)["더한줄"][0]["참조"]["키"] == a # 안 펼침 = 참조 그대로
|
||||
assert _calc(mine, _read(mine, b))["기준"]["계"] == 38696
|
||||
with store.at(mine), pytest.raises(store.StoreError):
|
||||
flat.flat_lines("sangeun", {**MINE, "키": a})
|
||||
doc, n = flat.reset("sangeun", {**_read(mine, a), "까닭": {"mid:일운반회수": "가정"}})
|
||||
assert n == 1 and not set(doc) & {"상수덮개", "까닭"}
|
||||
|
||||
@@ -18,7 +18,6 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Item_Sangeun as sk
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Library_Flat as flat
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
@@ -75,40 +74,6 @@ def _plus(**more):
|
||||
|
||||
|
||||
# ── 견본 금액 ─────────────────────────────────────────────────────────
|
||||
def test_변수_줄_할증율_견본():
|
||||
assert _sum(_doc(CARRY, _carry())) == 42917
|
||||
assert _sum(_plus()) == 51501 # _분석_650-H2 4 장
|
||||
var = [{"이름": "할증율", "식": "만약(운반거리 > 5, 20, 0)", "표시": 0, "자리": "mid:무게"}]
|
||||
assert _sum(_sk_doc(CARRY, _carry(), 변수줄=var, 식덮개={MAN: PLUS})) == 51501
|
||||
eng = PLUS.replace("×", "*")
|
||||
assert _sum(_sk_doc(CARRY, _carry(), 변수줄=var, 식덮개={MAN: eng})) == 51501 # 엔진 꼴도
|
||||
|
||||
|
||||
def test_합판거푸집_줄_식_고침():
|
||||
base = _sum(_doc(FORM, F211))
|
||||
assert base == 51419
|
||||
tool = "(형틀목공 × [노임 형틀목공] + 보통인부 × [노임 보통인부]) × 2 / 100"
|
||||
assert _sum(_sk_doc(FORM, F211, 식덮개={TOOL: tool})) == 51802 # = 790-2 공구손료 2 %
|
||||
more = "[합판거푸집설치및해체일당].형틀목공 × 1.1 / 시공량"
|
||||
got = _run(_sk_doc(FORM, F211, 식덮개={"mid:형틀목공": more}))
|
||||
line = next(x for x in got["줄"] if x["cid"] == "labor:LB000007#0")
|
||||
assert float(line["수량"]) == pytest.approx(5 * 1.1 / 45)
|
||||
assert got["기준"]["계"] > base
|
||||
|
||||
|
||||
def test_더한줄_수량식():
|
||||
add = {
|
||||
"종류": "인력",
|
||||
"요소": "LB000002",
|
||||
"수량": 1,
|
||||
"수량식": "무게 / 운반량 / 일운반회수 / 2",
|
||||
}
|
||||
got = _run(_sk_doc(CARRY, _carry(), 더한줄=[add]))
|
||||
one, mine = (next(x for x in got["줄"] if x["cid"] == c) for c in (MAN, "add:#0"))
|
||||
assert float(mine["수량"]) == pytest.approx(float(one["수량"]) / 2)
|
||||
for bad in ({"수량식": "1", "종류": "로직", "로직": FORM, "수량": 1},):
|
||||
with pytest.raises(sd.DocError, match="수만"):
|
||||
sd.clean(_sk_doc(FORM, F211, 더한줄=[bad]), None, _whole())
|
||||
|
||||
|
||||
# ── 이름 꼴 ↔ 엔진 식 ────────────────────────────────────────────────
|
||||
@@ -150,33 +115,7 @@ def test_꼴_상한_겹침():
|
||||
sd.clean(_sk_doc(FORM, F211, **bad), None, whole)
|
||||
|
||||
|
||||
def test_틀린_식은_그_자리만_M01_식():
|
||||
"""셈 길 = 틀린 자리만 M01 식 + 짝잃음 · 이름 겹친 변수 = 뺌."""
|
||||
doc = _sk_doc(
|
||||
CARRY,
|
||||
_carry(),
|
||||
변수줄=[{"이름": "무게", "식": "1", "자리": ""}],
|
||||
식덮개={MAN: "무게 / 없는것", "mid:없는줄": "1"},
|
||||
)
|
||||
got = _run(doc)
|
||||
assert got["기준"]["계"] == 42917
|
||||
why = {(x["cid"], x["까닭"]) for x in got["짝잃음"]}
|
||||
assert (MAN, "식 — 모르는 이름 「없는것」") in why
|
||||
assert ("mid:없는줄", "식 — 바탕에 없는 줄") in why
|
||||
assert any(c == "mid:무게" and "이미 있음" in w for c, w in why)
|
||||
|
||||
|
||||
# ── 옛 SK · 저장 · 셈 답 · 펼침 · 초기화 ─────────────────────────────────
|
||||
def test_옛_SK_그대로():
|
||||
whole = _whole()
|
||||
old = _sk_doc(
|
||||
FORM, F211, 덮개={"labor:LB000007#0": {"qty": 0.2}}, 상수덮개={"mid:시공량": {"2": 20}}
|
||||
)
|
||||
got = sd.clean(old, None, whole)
|
||||
assert not set(got) & set(fx.FIELDS) and not fx.has(got)
|
||||
row = whole.logic(FORM)
|
||||
assert fx.settle(row, got) == (row, [], got)
|
||||
assert _sum(_doc(FORM, F211)) == 51419 and _sum(old) == _sum({**old, "식덮개": {}})
|
||||
|
||||
|
||||
def _sk(folder, **doc):
|
||||
@@ -195,32 +134,6 @@ def _calc(folder, doc):
|
||||
return calc.calc_doc(doc)
|
||||
|
||||
|
||||
def test_저장_엔진_식_셈_답(world):
|
||||
mine = world["personal"]
|
||||
add = {"종류": "인력", "요소": "LB000002", "수량": 1, "수량식": "1 ÷ 일운반회수"}
|
||||
var = [{"이름": "할증율", "식": "20", "자리": ""}]
|
||||
key = _sk(mine, 바탕={"로직": CARRY}, 입력값=_carry(), 변수줄=var, 식덮개={MAN: PLUS})
|
||||
doc = _read(mine, key)
|
||||
assert doc["식덮개"] == {MAN: PLUS.replace("×", "*")} and doc["변수줄"] == var
|
||||
got = _calc(mine, doc)
|
||||
assert got["기준"]["계"] == 51501 and got["원래"]["계"] == 42917
|
||||
spot = got["시트"]["자리"][MAN]
|
||||
assert spot["식덮개"] is True and spot["덮개"] == ["식"] and spot["식글"] == PLUS
|
||||
assert spot["원식글"] == "무게 / 운반량 / 일운반회수" and spot["식"] == spot["원식글"]
|
||||
v = got["시트"]["자리"]["mid:할증율"]
|
||||
assert v["갈래"] == "변수" and v["식글"] == "20" and float(v["지금"]) == 20
|
||||
names = {(x["글"], x["갈래"]) for x in got["시트"]["이름표"]}
|
||||
assert {("할증율", "변수"), ("[인력운반기본공식]", "별칭"), ("노무비", "비목")} <= names
|
||||
assert ("[노임 보통인부]", "자원") in names # 호표 요소
|
||||
key2 = _sk(mine, 바탕={"로직": CARRY}, 입력값=_carry(), 더한줄=[add])
|
||||
doc2 = _read(mine, key2)
|
||||
assert doc2["더한줄"][0]["수량식"] == "1 / 일운반회수"
|
||||
assert _calc(mine, doc2)["시트"]["자리"]["add:#0"]["식글"] == "1 / 일운반회수"
|
||||
with store.at(mine), pytest.raises(store.StoreError) as e: # 틀린 식 저장 = 400
|
||||
refs.create("sangeun", {**_plus(식덮개={MAN: "무게 / 없는것"}), "더한줄": []})
|
||||
assert e.value.status == 400 and "모르는 이름" in str(e.value.detail)
|
||||
|
||||
|
||||
def test_펼침_막음_초기화_걷음(world):
|
||||
mine = world["personal"]
|
||||
a = _sk(mine, 바탕={"로직": CARRY}, 입력값=_carry(), 변수줄=[{"이름": "할증율", "식": "20"}])
|
||||
@@ -233,21 +146,6 @@ def test_펼침_막음_초기화_걷음(world):
|
||||
|
||||
|
||||
# ── B09 사본 굳힘 ─────────────────────────────────────────────────────
|
||||
def test_B09_굳힘_식_칸_그대로():
|
||||
whole = _whole()
|
||||
add = {"종류": "인력", "요소": "LB000002", "수량": 1, "수량식": "1 / 일운반회수"}
|
||||
doc = sd.clean({**_plus(), "더한줄": [add]}, None, whole)
|
||||
live = calc.run(doc, whole)["기준"]["계"]
|
||||
rid = "personal|7/42|SK-000001"
|
||||
frozen = sk.freeze({rid: doc})[rid]
|
||||
row, key = frozen[sk.ROW], frozen["바탕"]["로직"]
|
||||
assert key.startswith("GX9") and frozen["원본"]["식덮개"] == doc["식덮개"]
|
||||
assert [x["이름"] for x in row["중간"]][0] == "할증율"
|
||||
assert row["호표"][0]["수량"] == PLUS.replace("×", "*")
|
||||
assert row["호표"][1]["수량"] == "1 / 일운반회수"
|
||||
over = calc._Over(whole, key, json.loads(json.dumps(row)))
|
||||
again = calc.run(sd.clean(frozen, None, over), over)["기준"]["계"]
|
||||
assert again == live and float(live) > 51501
|
||||
|
||||
|
||||
def test_같은_내용_지문_식_칸_가림():
|
||||
|
||||
@@ -113,10 +113,3 @@ def test_층_섞임_없음_개인_자재는_그때_층에서만(world):
|
||||
assert Decimal(str(mine["기준단가"])) == 1234
|
||||
assert theirs["기준단가"] is None
|
||||
assert code not in whole.index.get(code[:2], {})
|
||||
|
||||
|
||||
def test_상수_덮개_셈_답_전후_같음():
|
||||
got = calc.calc_doc(_sk(상수덮개={"pct:공구손료 및 경장비#0": {"0": 2}}))
|
||||
assert got["기준"]["계"] == 51802
|
||||
assert got["원래"]["계"] == 51419
|
||||
assert got["시트"]["자리"]["pct:공구손료 및 경장비#0"]["덮개"] == ["상수"]
|
||||
|
||||
@@ -182,7 +182,6 @@ def test_셈_답_원래_엑셀_원본_글(world):
|
||||
assert view["단가기준"] == "엑셀" and view["파일"] == "봉화.xlsx" and view["행"] == [2909, 2943]
|
||||
lines = view["글줄"]
|
||||
assert lines[0] == {"행": 2909, "글": "합판거푸집 ㎡ 당", "자리": None}
|
||||
assert lines[1]["같음"] is True and lines[2]["같음"] is False # 덮은 줄 = 엑셀과 다름
|
||||
assert [x["이름"] for x in view["이음없음"]] == ["합판(내수)", "각재", "형틀목공"]
|
||||
|
||||
|
||||
@@ -382,8 +381,6 @@ def test_실무_블록_가져온_식(tag, code, world):
|
||||
assert check["같음"] is True and check["셈"] == excel and len(check["줄"]) >= 3
|
||||
assert all(":" in x["자리"] for x in check["줄"]) # 줄 이름 → cid · mid: · 단계:
|
||||
assert ans["원래"] == out["원본"]["엑셀금액"] and round(ans["기준"]["계"]) == excel["계"]
|
||||
shown = [x for x in ans[imp.KEY]["글줄"] if "같음" in x]
|
||||
assert shown and all(x["같음"] for x in shown)
|
||||
assert _frozen_total(doc, _whole()) == excel["계"]
|
||||
ours = imp.to_price(doc, "우리")
|
||||
assert {k: round(float(v)) for k, v in ours["전"].items()} == excel
|
||||
|
||||
@@ -81,10 +81,6 @@ def _sum(folder, key):
|
||||
return _calc(folder, _doc(folder, key))["기준"]["계"]
|
||||
|
||||
|
||||
def _cids(folder, key):
|
||||
return [x["cid"] for x in _calc(folder, _doc(folder, key))["줄"]]
|
||||
|
||||
|
||||
def _changed(row, at=0):
|
||||
row = copy.deepcopy(row)
|
||||
row["호표"][at]["수량"] = f"({row['호표'][at]['수량']}) * 2"
|
||||
@@ -115,7 +111,7 @@ def test_price_refresh_only_on_press(world, monkeypatch):
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": PCT})
|
||||
was = _sum(me, key)
|
||||
lb = _cids(me, key)[0].split(":")[1].split("#")[0]
|
||||
lb = next(r["키"] for r in _doc(me, key)["사본"]["단가"] if r["키"].startswith("LB"))
|
||||
row = copy.deepcopy(_live().get(lb))
|
||||
row["값"] = row["값"] * 2
|
||||
_fake(monkeypatch, [row])
|
||||
@@ -133,35 +129,12 @@ def test_price_refresh_only_on_press(world, monkeypatch):
|
||||
assert saved["사본"]["단가시점"] >= saved["사본"]["시점"]
|
||||
|
||||
|
||||
def test_regen_reapplies_covers(world, monkeypatch):
|
||||
"""③ [재생성] — 덮개 · 까닭 새 사본에 다시 얹힘 · 없어진 줄 덮개 = 못얹은 · 배지 꺼짐."""
|
||||
me = world["personal"]
|
||||
probe = _sk(me, 바탕={"로직": PCT})
|
||||
one, two = _cids(me, probe)[:2]
|
||||
covers = {one: {"qty": 0.5}, two: {"qty": 0.7}}
|
||||
key = _sk(me, 바탕={"로직": PCT}, 덮개=covers, 까닭={one: "현장 실측"})
|
||||
row = copy.deepcopy(_live().logic(PCT))
|
||||
row["호표"] = [x for n, x in enumerate(row["호표"]) if n != 1] # 둘째 줄 없앤 새 판
|
||||
_fake(monkeypatch, [row])
|
||||
with store.at(me):
|
||||
got = skc.preview(_doc(me, key), skc.REGEN)
|
||||
assert [x["cid"] for x in got["못얹은"]] == [two]
|
||||
assert got["전"]["계"] != got["후"]["계"]
|
||||
_save(me, key, got["문서"])
|
||||
doc = _doc(me, key)
|
||||
assert doc["덮개"][one]["qty"] == 0.5 and doc["까닭"][one] == "현장 실측"
|
||||
now = _calc(me, doc)
|
||||
assert now["줄"][0]["덮개"] == ["qty"]
|
||||
assert now["사본"]["M01새판"] is False
|
||||
assert now["기준"]["계"] == got["후"]["계"]
|
||||
|
||||
|
||||
def test_deleted_keys_keep_last_value(world, monkeypatch):
|
||||
"""⑤ 사본이 부르는 M01 키(바탕 로직 · 노임)가 지워져도 마지막 값 · 지운키 표지."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": PCT})
|
||||
was = _sum(me, key)
|
||||
lb = _cids(me, key)[0].split(":")[1].split("#")[0]
|
||||
lb = next(r["키"] for r in _doc(me, key)["사본"]["단가"] if r["키"].startswith("LB"))
|
||||
_fake(monkeypatch, drop=[PCT, lb])
|
||||
with pytest.raises(Exception):
|
||||
m01.loaded()[1].logic(PCT)
|
||||
|
||||
@@ -109,23 +109,6 @@ def test_price_refresh_only_on_press(world, monkeypatch):
|
||||
assert _calc(me, sc)["사본"]["단가새값"] is False
|
||||
|
||||
|
||||
def test_regen_reapplies_line_cover(world, monkeypatch):
|
||||
"""③ [재생성] — 줄 덮개(cid) 새 사본에 다시 얹힘 · 배지 꺼짐."""
|
||||
me = world["personal"]
|
||||
two = {"덮개": {f"labor:{LB}#0": {"qty": 0.5}, "labor:LB000002#0": {"qty": 0.7}}}
|
||||
_labor(me, [{"로직": PCT, "수량": {"손": 1}, "패치": two}])
|
||||
row = copy.deepcopy(_live().logic(PCT))
|
||||
row["호표"] = [x for n, x in enumerate(row["호표"]) if n != 1] # 둘째 줄 없앤 새 판
|
||||
_fake(monkeypatch, [row])
|
||||
assert not _calc(me, COL)["줄"][0].get("짝잃음") # 사본 = 옛 판 그대로
|
||||
was = _calc(me, COL)["기준합"]["계"]
|
||||
_write(me, "labor", COL, {**_read(me, "labor", COL), lc.JOB: lc.REGEN})
|
||||
doc = _read(me, "labor", COL)
|
||||
assert doc["담은로직"][0]["패치"]["덮개"][f"labor:{LB}#0"] == {"qty": 0.5}
|
||||
now = _calc(me, COL)
|
||||
assert now["사본"]["M01새판"] is False and now["기준합"]["계"] != was
|
||||
|
||||
|
||||
def test_layer_and_column_copy_keep_copy(world, monkeypatch):
|
||||
"""④ 층 사이 복사(회사 → 개인) · 열 복사 = 원본 사본 그대로(지금 M01 로 다시 안 찍음)."""
|
||||
co, me = world["company"], world["personal"]
|
||||
|
||||
@@ -8,24 +8,17 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
|
||||
import pytest
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Copy as skc
|
||||
from M02_MasterTemplete import M02_Sangeun_Equation as eqm
|
||||
from M02_MasterTemplete import M02_Sangeun_Imported as imp
|
||||
from resources.tester.test_795_1_sk_copy import (
|
||||
_calc,
|
||||
_doc,
|
||||
_fake,
|
||||
_imported_row,
|
||||
_live,
|
||||
_save,
|
||||
_sk,
|
||||
_sum,
|
||||
)
|
||||
from resources.tester.test_m02_labor_ref import world # noqa: F401 — 같은 임시 층
|
||||
|
||||
@@ -42,47 +35,6 @@ KEY = "GC000211" # 합판거푸집 — 중간 시공량 · 형틀목공 · 보
|
||||
DOUBLE = [{"할일": "식", "자리": "호표:0", "식": "형틀목공 × 2", "까닭": "sub2임시 시험"}]
|
||||
|
||||
|
||||
def test_edit_changes_amount_save_is_canonical(world):
|
||||
"""③ 고침 [저장] = 고침 목록 남음 · 서버 셈 = 금액 바뀜 · 원래 대비 · M01 그대로 · 틀린 고침 400."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": KEY})
|
||||
was = _sum(me, key)
|
||||
m01_row = copy.deepcopy(_live().logic(KEY))
|
||||
doc = {**_doc(me, key), eqm.KEY: DOUBLE}
|
||||
_save(me, key, doc)
|
||||
saved = _doc(me, key)
|
||||
assert saved[eqm.KEY][0]["까닭"] == "sub2임시 시험"
|
||||
assert saved["사본"]["로직"][0]["호표"][0]["수량"] == m01_row["호표"][0]["수량"] # 사본 = 원래
|
||||
now = _calc(me, saved)
|
||||
after = now["기준"]["계"]
|
||||
assert after > was
|
||||
assert now["원래"]["계"] == was # 원래 대비 = 고침 없는 사본
|
||||
assert _live().logic(KEY) == m01_row # M01 정본 안 바뀜
|
||||
bad = {**saved, eqm.KEY: [{"할일": "식", "자리": "호표:0", "식": "없는값 × 2"}]}
|
||||
with pytest.raises(store.StoreError):
|
||||
_save(me, key, bad)
|
||||
assert _sum(me, key) == after
|
||||
|
||||
|
||||
def test_variables_add_drop_rename(world):
|
||||
"""④ 변수 더함 → 식에서 부름(금액 바뀜) · 쓰는 변수 지움 = 저장 400 · 기호 = 금액 그대로."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": KEY})
|
||||
doc = _doc(me, key)
|
||||
was = _calc(me, doc)["기준"]
|
||||
add = [
|
||||
{"할일": "더함", "갈래": "중간", "열쇠": "할증", "식": "1.5", "뒤": "보통인부"},
|
||||
{"할일": "식", "자리": "호표:1", "식": "보통인부 × 할증"},
|
||||
]
|
||||
_save(me, key, {**doc, eqm.KEY: add})
|
||||
assert _calc(me, _doc(me, key))["기준"]["노무비"] > was["노무비"]
|
||||
with pytest.raises(store.StoreError):
|
||||
_save(me, key, {**_doc(me, key), eqm.KEY: [{"할일": "지움", "열쇠": "시공량"}]})
|
||||
sign = [{"할일": "변수", "열쇠": "시공량", "기호": "Q", "아래": "d", "이름": "하루 시공량"}]
|
||||
_save(me, key, {**_doc(me, key), eqm.KEY: sign})
|
||||
assert _calc(me, _doc(me, key))["기준"]["계"] == was["계"] # 이름만 — 금액 그대로
|
||||
|
||||
|
||||
def test_imported_same_path(world):
|
||||
"""⑥ 가져온 식 SK(바탕 null · 가져온.로직) — 같은 고침 · 저장."""
|
||||
me = world["personal"]
|
||||
@@ -97,28 +49,6 @@ def test_imported_same_path(world):
|
||||
assert _doc(me, key)["가져온"]["로직"]["호표"][0]["수량"] == "0.5" # 엑셀 줄 그대로
|
||||
|
||||
|
||||
def test_m01_change_kept_regen_reapplies(world, monkeypatch):
|
||||
"""⑦ M01 바뀌어도 고친 SK 그대로 · [재생성] = 새 사본에 고침 다시 · 자리 없으면 못얹은."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": KEY})
|
||||
_save(me, key, {**_doc(me, key), eqm.KEY: DOUBLE})
|
||||
was = _sum(me, key)
|
||||
row = copy.deepcopy(_live().logic(KEY))
|
||||
row["호표"][1]["수량"] = f"({row['호표'][1]['수량']}) * 3"
|
||||
_fake(monkeypatch, [row])
|
||||
assert _sum(me, key) == was
|
||||
with store.at(me):
|
||||
got = skc.preview(_doc(me, key), skc.REGEN)
|
||||
assert not got["못얹은"] and got["후"]["계"] > was # 새 판 + 같은 고침
|
||||
gone = copy.deepcopy(row)
|
||||
gone["호표"] = []
|
||||
_fake(monkeypatch, [gone])
|
||||
with store.at(me):
|
||||
got = skc.preview(_doc(me, key), skc.REGEN)
|
||||
assert eqm.LOST in [x["cid"] for x in got["못얹은"]] # 그 밖 = 없어진 줄 M01판(790-2)
|
||||
assert m01.loaded()[1].logic(KEY)["호표"] == []
|
||||
|
||||
|
||||
def test_screen_same_part_first_tab():
|
||||
"""화면 — M02 수식 = 공용 수식 문서 화면(802-4b-2 · 옛 수식 나무 화면 걷음) · 첫 탭 · 옛 탭 걷음(799-2)."""
|
||||
import re
|
||||
|
||||
@@ -38,8 +38,6 @@ def _manual(monkeypatch):
|
||||
|
||||
|
||||
FORM = "GC000211" # 합판거푸집(옵션 많음)
|
||||
BASIC = "GF000089" # 토사깍기(기계) — 굴착기 시간당 × 1 / 작업량(813-2 GC001148 지움 뒤)
|
||||
ADD = {"종류": "로직", "로직": BASIC, "수량": 2, "입력값": {}, "이름": "sub2임시 굴착기"}
|
||||
|
||||
|
||||
def _sum(folder, key):
|
||||
@@ -139,26 +137,33 @@ def test_regen_takes_m01_doc_drops_edits(world, monkeypatch):
|
||||
assert got["사본"]["M01새판"] is False and got["사본"]["문서새판"] == []
|
||||
|
||||
|
||||
CALLER, CALLED = "GC000006", "GC000267" # 가설울타리 강관 지주 → 굴착기(무한궤도) 시간당
|
||||
|
||||
|
||||
def test_link_follows_on_regen_unlink_freezes(world, monkeypatch):
|
||||
"""⑤ 단가산출 연결 = 부름 사본(M01 바뀌어도 그대로 · [재생성] 때 따라감) · 끊기 = 사본 안 고침."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": FORM}, 더한줄=[copy.deepcopy(ADD)])
|
||||
key = _sk(
|
||||
me, 바탕={"로직": CALLER}, 단위="m"
|
||||
) # 기초 문서가 부르는 단가산출(855 2-C1 — 옛 더한줄 대신)
|
||||
was = _sum(me, key)
|
||||
read = _at(me, path.read, key)
|
||||
assert BASIC in read["부름"]
|
||||
cut = {BASIC: _twice(read["부름"][BASIC])}
|
||||
assert CALLED in read["부름"]
|
||||
cut = {CALLED: _twice(read["부름"][CALLED])}
|
||||
pre = _at(me, path.preview, key, {"끊음": cut})
|
||||
assert pre["후"]["계"] > was
|
||||
saved = _at(me, path.save, key, {"끊음": cut, "판": read["판"]})
|
||||
assert saved["끊음"][BASIC] == {**cut[BASIC], "키": BASIC} and _sum(me, key) == pre["후"]["계"]
|
||||
_fake(monkeypatch, [_changed(_live().logic(BASIC))]) # 원본 바뀜
|
||||
assert (
|
||||
saved["끊음"][CALLED] == {**cut[CALLED], "키": CALLED} and _sum(me, key) == pre["후"]["계"]
|
||||
)
|
||||
_fake(monkeypatch, [_changed(_live().logic(CALLED))]) # 원본 바뀜
|
||||
assert _sum(me, key) == pre["후"]["계"] # 끊은 것 · 연결 모두 그대로(누르기 전)
|
||||
with pytest.raises(store.StoreError) as e: # 부르지 않는 키 끊기
|
||||
_at(me, path.preview, key, {"끊음": {"GC999999": read["부름"][BASIC]}})
|
||||
_at(me, path.preview, key, {"끊음": {"GC999999": read["부름"][CALLED]}})
|
||||
assert e.value.status == 400
|
||||
read = _at(me, path.read, key)
|
||||
pre = _at(me, path.preview, key, {"할일": "재생성"})
|
||||
assert pre["버림"]["끊음"] == [BASIC]
|
||||
assert pre["버림"]["끊음"] == [CALLED]
|
||||
got = _at(me, path.save, key, {"할일": "재생성", "판": read["판"]})
|
||||
assert got["끊음"] == {} and got["셈"]["계"] > was # 연결 = 새 원본 따라감
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ from resources.tester.test_m02_structure import write_sample_table
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
FORM = "GC000211" # 합판거푸집 — 폼타이 · 측압 · 규격 옵션
|
||||
BASIC = "GF000089" # 토사깍기(기계) — 굴착기 시간당 × 1 / 작업량(813-2 GC001148 지움 뒤)
|
||||
ADD = {"종류": "로직", "로직": BASIC, "수량": 2, "입력값": {}, "이름": "sub3임시 굴착기"}
|
||||
|
||||
|
||||
def _at(folder, fn, *args):
|
||||
@@ -82,27 +80,27 @@ def _replay(read: dict) -> dict:
|
||||
return dc.mc.calc(doc, _Replay(read["연결"]))
|
||||
|
||||
|
||||
CALLER, CALLED = "GC000006", "GC000267" # 가설울타리 강관 지주 → 굴착기(무한궤도) 시간당
|
||||
|
||||
|
||||
def test_연결기록만으로_같은셈_끊음먼저(world):
|
||||
me = world["personal"]
|
||||
key = _sk(
|
||||
me,
|
||||
바탕={"로직": FORM},
|
||||
입력값={"폼타이": "사용", "측압": "4t/㎡"},
|
||||
더한줄=[copy.deepcopy(ADD)],
|
||||
)
|
||||
me, 바탕={"로직": CALLER}, 단위="m"
|
||||
) # 기초 문서가 부르는 단가산출(855 2-C1 — 옛 더한줄 대신)
|
||||
read = _at(me, path.read, key)
|
||||
rec = read["연결"]
|
||||
assert {"요소", "표", "문서", "이름"} <= set(rec) and BASIC in rec["문서"]
|
||||
assert {"요소", "표", "문서", "이름"} <= set(rec) and CALLED in rec["문서"]
|
||||
assert _replay(read)["계"] == read["셈"]["계"]
|
||||
cut = copy.deepcopy(read["부름"][BASIC])
|
||||
cut = copy.deepcopy(read["부름"][CALLED])
|
||||
line = cut["금액"][0]
|
||||
line["수량"] = f"({line.get('수량') or 1}) × 2" # 끊은 문서 안 줄 고침
|
||||
saved = _at(me, path.save, key, {"끊음": {BASIC: cut}, "판": read["판"]})
|
||||
assert saved["연결"]["문서"][BASIC]["금액"][0]["수량"] == line["수량"] # 끊음 먼저
|
||||
saved = _at(me, path.save, key, {"끊음": {CALLED: cut}, "판": read["판"]})
|
||||
assert saved["연결"]["문서"][CALLED]["금액"][0]["수량"] == line["수량"] # 끊음 먼저
|
||||
assert saved["셈"]["계"] > read["셈"]["계"]
|
||||
assert _replay(saved)["계"] == saved["셈"]["계"]
|
||||
again = _at(me, path.read, key)
|
||||
assert again["끊음"][BASIC]["금액"][0]["수량"] == line["수량"] and again["판"] == saved["판"]
|
||||
assert again["끊음"][CALLED]["금액"][0]["수량"] == line["수량"] and again["판"] == saved["판"]
|
||||
got = _at(me, path.save, key, {"끊음": {}, "판": again["판"]}) # 다시 잇기
|
||||
assert got["끊음"] == {} and got["셈"]["계"] == read["셈"]["계"]
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
- 옮긴 뒤 상태 = 마스터 층 로직 줄 0(한 번용 옮기기 도구는 894 에서 걷음)
|
||||
"""
|
||||
|
||||
import copy
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
@@ -15,13 +16,12 @@ from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from common_util.common_util_auth import verify_session
|
||||
from M02_MasterTemplete import M02_Doc_Sk_Path as sk_path
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
from M02_MasterTemplete import M02_Labor_SkRow as skrow
|
||||
from M02_MasterTemplete import M02_Library_Flat as flat
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from M02_MasterTemplete import M02_Sangeun_Doc as sd
|
||||
from M02_MasterTemplete import M02_Sangeun_Router as sk_router
|
||||
from M02_MasterTemplete import M02_Template_Layers as layers
|
||||
from M02_MasterTemplete.M02_Labor_Expand import Expand
|
||||
@@ -60,11 +60,11 @@ def test_모달_저장_SK_문서_뒤_일위대가_따라감(world):
|
||||
sk = _make(me, "sangeun", 이름="sub1임시 SK", 바탕={"로직": TEN})
|
||||
sc = _make(me, "precombo", 이름="sub1임시 SC", 담은로직=[{"참조": {**MINE, "키": sk}, "수량": {"손": 1}}]) # fmt: skip
|
||||
before = _value(me, sc)["계"]
|
||||
with store.at(me): # 모달 [저장] = 그 SK 문서 쓰기(`saveTemplate` sangeun)
|
||||
now = store.read("sangeun", sk)
|
||||
cid = sd.line_ids(_whole().logic(TEN))[0]
|
||||
doc = {**now["문서"], "덮개": {cid: {"배율": 2}}}
|
||||
store.write("sangeun", sk, now["판"], calc.clean_doc(doc, refs.here()))
|
||||
with store.at(me): # 모달 [저장] = 그 SK 수식 문서 저장(`Labor_SkEdit` · 수식 길)
|
||||
read = sk_path.read(sk)
|
||||
twice = copy.deepcopy(read["문서"])
|
||||
twice["금액"][0]["수량"] = f"({twice['금액'][0].get('수량') or 1}) × 2"
|
||||
sk_path.save(sk, {"문서": twice, "판": read["판"]})
|
||||
assert _value(me, sc)["계"] != before # 일위대가 금액이 SK 를 따라감
|
||||
assert _read(me, "precombo", sc)["담은로직"][0]["참조"]["키"] == sk # 일위대가 문서는 그대로
|
||||
|
||||
|
||||
@@ -52,9 +52,17 @@ def _easy(**vals):
|
||||
|
||||
|
||||
def _sk(folder, machine_no):
|
||||
line = {"종류": "로직", "로직": "GC000268", "입력값": {"기계": machine_no, "지역": "전국평균"},
|
||||
"수량": "1"} # fmt: skip
|
||||
body = {"이름": "sub3임시 내기계", "단위": "시간", "더한줄": [line]}
|
||||
given = {
|
||||
"기계": machine_no,
|
||||
"지역": "전국평균",
|
||||
} # 바탕 로직 + 입력값(855 2-C1 — 옛 더한줄 대신)
|
||||
body = {
|
||||
"이름": "sub3임시 내기계",
|
||||
"단위": "시간",
|
||||
"바탕": {"로직": "GC000268"},
|
||||
"입력값": given,
|
||||
"더한줄": [],
|
||||
}
|
||||
return _at(folder, lambda: refs.create("sangeun", body)["이름"])
|
||||
|
||||
|
||||
|
||||
@@ -187,21 +187,6 @@ OLD_ADDS = {
|
||||
} # fmt: skip
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", list(OLD_ADDS))
|
||||
def test_old_added_lines(world, monkeypatch, name):
|
||||
"""옛 로직 길 더한줄(로직 기계 · 재료 요소 · 인력 요소) — 저장 뒤 그대로 · 갱신 뒤 반영."""
|
||||
me = world["personal"]
|
||||
adds, given, moved = OLD_ADDS[name]
|
||||
key = _sk(me, 더한줄=adds, 입력값=given)
|
||||
was = _sum(me, key)
|
||||
assert was > 0
|
||||
assert _at(me, path.read, key)["사본"]["사본없음"] == 0
|
||||
_move(monkeypatch, moved)
|
||||
assert _sum(me, key) == was
|
||||
got = _price(me, key)
|
||||
assert moved in got["바뀐"] and got["후"] > was
|
||||
|
||||
|
||||
# ── 가져온 식 · 층 복사 · 재생성 ──────────────────────────────────────
|
||||
def test_imported_ours(world, monkeypatch):
|
||||
"""가져온 식 단가기준 우리 — 이음 노임 바뀌어도 그대로 · 갱신 뒤 반영 · 엑셀 기준 = 엑셀 값."""
|
||||
|
||||
@@ -179,13 +179,17 @@ def test_direct_formula_my_machine(world):
|
||||
whole = _at(me, mym.whole)
|
||||
run = m01.cm.mf.run(whole, DIRECT, {"기계": no}) # 직접 값 식 — 내 기계 원문번호를 받음
|
||||
assert (run["노무비"], run["재료비"], run["경비"]) == (10, 20, 30)
|
||||
line = {"종류": "로직", "로직": DIRECT, "입력값": {"기계": no}, "수량": "2"}
|
||||
name = _at(
|
||||
me, lambda: refs.create("sangeun", {"이름": NAME, "단위": "시간", "더한줄": [line]})["이름"]
|
||||
)
|
||||
body = {
|
||||
"이름": NAME,
|
||||
"단위": "시간",
|
||||
"바탕": {"로직": DIRECT},
|
||||
"입력값": {"기계": no},
|
||||
"더한줄": [],
|
||||
}
|
||||
name = _at(me, lambda: refs.create("sangeun", body)["이름"]) # 855 2-C1 — 옛 더한줄 대신 바탕
|
||||
doc = _at(me, lambda: store.read("sangeun", name)["문서"])
|
||||
got = _at(me, calc.calc_doc, doc, None, False)["기준"]
|
||||
assert (got["노무비"], got["재료비"], got["경비"]) == (20, 40, 60)
|
||||
assert (got["노무비"], got["재료비"], got["경비"]) == (10, 20, 30)
|
||||
|
||||
|
||||
# ⑤ 전력 줄 ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -211,7 +211,7 @@ def test_old_big_copy_reads_then_slims(world):
|
||||
|
||||
|
||||
def test_save_path_once(world, monkeypatch):
|
||||
"""SK 다시 저장 한 번 — M01 모으기 0 · SK 파일 읽기(셈 쪽) 한 번 · 옛 셈 한 번."""
|
||||
"""SK 다시 저장 한 번 — M01 모으기 0 · SK 파일 읽기(셈 쪽) 한 번 · 옛 셈 0(855 2-C1)."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": DIG_BASE}, 단위="㎥")
|
||||
count = {"모으기": 0, "읽기": 0, "셈": 0}
|
||||
@@ -236,7 +236,7 @@ def test_save_path_once(world, monkeypatch):
|
||||
monkeypatch.setattr(Path, "read_bytes", reading)
|
||||
store.write("sangeun", key, got["판"], got["문서"])
|
||||
# 읽기 = 사본 정함 한 번 + 판 맞춤(쓰기 전) + 새 판(쓰기 뒤)
|
||||
assert count == {"모으기": 0, "읽기": 3, "셈": 1}
|
||||
assert count == {"모으기": 0, "읽기": 3, "셈": 0} # 옛 SK 셈 길 안 돎(855 2-C1)
|
||||
|
||||
|
||||
def test_doc_path_save_keeps_both_slots(world):
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# ruff: noqa: F811 — 임시 층 fixture(world)를 test_m02_labor_ref 에서 받아 씀
|
||||
"""855-A 지킴 ③ — 단가산출(SK) 셈 답 · 견본 꼴마다 옛 엔진 길(`M02_Doc_Sk.OLD`) 대 지금 길(수식 사본 →
|
||||
문서 계산기) · 지금 길 답의 줄 비목 합(원 버림) = 기준.
|
||||
"""855 지킴 ③ — 단가산출(SK) 셈 답 = 수식 사본 문서 셈 한 길(2-C1) · 견본 꼴마다.
|
||||
|
||||
견본(임시 storage · 개인 층 · M01 은 읽기만): 바탕 로직 · 옛 칸 값(더한줄 로직) · 율 더한줄 · 형제 SK(바탕 참조) ·
|
||||
「따로」(수식 사본을 고쳐 저장) · 가져온 식(엑셀 줄 · 저장 없음).
|
||||
걸음 2-C1(SK 셈 한 길)이 이 시험을 자로 씀 — 「따로」 단언은 지금 사실(줄 = 옛 · 기준 = 새)이고 2-C1 에서 뒤집음.
|
||||
견본(임시 storage · 개인 층 · M01 은 읽기만): 바탕 로직 · 율 바탕 · 형제 SK(바탕 참조로 만듦) ·
|
||||
「따로」(수식 사본을 고쳐 저장) · 가져온 식(엑셀 줄 · 저장 없음) · 옛 칸 고침(더한줄 로직 · 율 더한줄).
|
||||
판정 — 셈 답 기준 = 수식 길 셈(`M02_Doc_Sk_Path` · 화면 줄 쌓기와 같은 계산기) · 줄 비목 합(원 버림 ·
|
||||
합밖 줄 뺌) = 기준 · 줄 수 > 0 · 옛 칸 고침 SK = 못 셈 + 까닭 하나(옛 엔진 안 돎 · 올림 없음).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -17,6 +17,7 @@ import pytest
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Doc_Sk as dsk
|
||||
from M02_MasterTemplete import M02_Doc_Sk_Path as path
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
||||
from M02_MasterTemplete import M02_Sangeun_Calc as calc
|
||||
from M02_MasterTemplete import M02_Sangeun_Doc as sd
|
||||
@@ -38,18 +39,10 @@ def _manual(monkeypatch):
|
||||
monkeypatch.setattr(renew, "on", lambda: False)
|
||||
|
||||
|
||||
def _run(doc: dict, old: bool) -> dict:
|
||||
def _run(folder, doc: dict) -> dict:
|
||||
whole = m01.loaded()[1]
|
||||
token = dsk.OLD.set(old)
|
||||
try:
|
||||
return calc.run(sd.clean(doc, None, whole), whole)
|
||||
finally:
|
||||
dsk.OLD.reset(token)
|
||||
|
||||
|
||||
def _both(folder, doc) -> tuple[dict, dict]:
|
||||
with store.at(folder):
|
||||
return _run(doc, True), _run(doc, False)
|
||||
return calc.run(sd.clean(doc, None, whole), whole)
|
||||
|
||||
|
||||
def _lines_sum(got: dict) -> dict:
|
||||
@@ -57,7 +50,7 @@ def _lines_sum(got: dict) -> dict:
|
||||
for ln in got.get("줄") or []:
|
||||
for k in COSTS:
|
||||
v = (ln.get("비목") or {}).get(k)
|
||||
total[k] += Decimal(str(v)) if v is not None else 0
|
||||
total[k] += Decimal(str(v)) if v is not None and not ln.get("합밖") else 0
|
||||
return {k: v.quantize(Decimal(1), ROUND_DOWN) for k, v in total.items()}
|
||||
|
||||
|
||||
@@ -65,53 +58,80 @@ def _base(got: dict) -> dict:
|
||||
return {k: Decimal(str(got["기준"][k])).quantize(Decimal(1), ROUND_DOWN) for k in COSTS}
|
||||
|
||||
|
||||
def _same_paths(old: dict, new: dict) -> None:
|
||||
assert old["기준"] is not None and new["기준"] is not None
|
||||
assert {k: Decimal(str(old["기준"][k])) for k in COSTS} == {
|
||||
k: Decimal(str(new["기준"][k])) for k in COSTS
|
||||
}
|
||||
assert _lines_sum(new) == _base(new)
|
||||
def _one_path(got: dict, screen: dict | None = None) -> None:
|
||||
"""한 길 — 문서 셈 · 줄 있음 · 줄 합 = 기준 · (있으면) 수식 길 셈과 같음."""
|
||||
assert got["수식셈"]["셈됨"] is True and got["기준"] is not None
|
||||
assert len(got["줄"]) > 0
|
||||
assert _lines_sum(got) == _base(got)
|
||||
if screen is not None:
|
||||
assert {k: Decimal(str(got["기준"][k])) for k in COSTS} == {
|
||||
k: Decimal(str(screen[k])) for k in COSTS
|
||||
}
|
||||
|
||||
|
||||
def _screen(folder, key: str) -> dict:
|
||||
with store.at(folder):
|
||||
return path.read(key)["셈"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"body",
|
||||
[{"바탕": {"로직": FORM}}, {"바탕": {"로직": PCT}}],
|
||||
ids=["바탕", "율_바탕"],
|
||||
)
|
||||
def test_층_SK_한_길_줄_합_기준(world, body):
|
||||
me = world["personal"]
|
||||
key = _sk(me, **copy.deepcopy(body))
|
||||
_one_path(_run(me, _doc(me, key)), _screen(me, key))
|
||||
|
||||
|
||||
def test_옛_엔진_안_돎(world, monkeypatch):
|
||||
"""한 번 셈에 옛 엔진(`run_line`) 부름 0."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": FORM})
|
||||
hits = []
|
||||
real = labor.run_line
|
||||
monkeypatch.setattr(labor, "run_line", lambda *a, **k: hits.append(1) or real(*a, **k))
|
||||
_one_path(_run(me, _doc(me, key)))
|
||||
assert hits == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"body",
|
||||
[
|
||||
{"바탕": {"로직": FORM}},
|
||||
{"바탕": {"로직": PCT}},
|
||||
{"바탕": {"로직": FORM}, "더한줄": [ADD]}, # 옛 칸 값(더한줄 로직)
|
||||
{"바탕": {"로직": SUB}, "더한줄": [_rate("인력", 2)], "단위": "주"}, # 율 더한줄
|
||||
],
|
||||
ids=["바탕", "율_바탕", "옛칸_더한줄", "율_더한줄"],
|
||||
ids=["옛칸_더한줄", "율_더한줄"],
|
||||
)
|
||||
def test_층_SK_옛_대_새_같고_줄_합_기준(world, body):
|
||||
def test_옛_칸_고침_SK_못_셈_까닭(world, body):
|
||||
me = world["personal"]
|
||||
key = _sk(me, **copy.deepcopy(body))
|
||||
doc = _doc(me, key)
|
||||
old, new = _both(me, doc)
|
||||
assert "수식셈" in new # 지금 길 = 수식 사본 문서 셈
|
||||
_same_paths(old, new)
|
||||
got = _run(me, _doc(me, key))
|
||||
assert got["기준"] is None and got["줄"] == []
|
||||
assert got["까닭"] == dsk.OLD_WHY
|
||||
assert calc.unit(_doc(me, key), m01.loaded()[1], None, ())["까닭"] == dsk.OLD_WHY
|
||||
|
||||
|
||||
def test_형제_SK_바탕_참조(world):
|
||||
me = world["personal"]
|
||||
first = _sk(me, 바탕={"로직": FORM})
|
||||
second = _sk(me, 바탕={"참조": {"층": "personal", "주인": "7/42", "키": first}})
|
||||
old, new = _both(me, _doc(me, second))
|
||||
_same_paths(old, new)
|
||||
assert new["기준"] == _both(me, _doc(me, first))[1]["기준"]
|
||||
new = _run(me, _doc(me, second))
|
||||
_one_path(new)
|
||||
assert new["기준"] == _run(me, _doc(me, first))["기준"]
|
||||
|
||||
|
||||
def test_가져온_식_옛_대_새(world):
|
||||
old, new = _both(world["personal"], imported._doc())
|
||||
assert "수식셈" in new
|
||||
_same_paths(old, new)
|
||||
def test_가져온_식(world):
|
||||
new = _run(world["personal"], imported._doc())
|
||||
_one_path(new)
|
||||
|
||||
|
||||
def test_따로_SK_지금은_줄_옛_기준_새(world):
|
||||
"""「따로」 = 고친 수식 사본이 정본 — 지금 셈 답은 줄 = 옛 엔진(옛 칸) · 기준 = 문서 계산기라 갈림.
|
||||
2-C1 에서 뒤집을 단언 — 그 뒤엔 `_same_paths` 꼴(줄 합 = 기준)로 바꿈."""
|
||||
def test_따로_SK_줄도_문서_답(world):
|
||||
"""「따로」 = 고친 수식 사본이 정본 — 줄 · 기준 모두 그 문서 셈(2-C1 전에는 줄 = 옛 엔진으로 갈렸음)."""
|
||||
me = world["personal"]
|
||||
key = _sk(me, 바탕={"로직": PCT})
|
||||
plain = _run(me, _doc(me, key))
|
||||
with store.at(me):
|
||||
read = path.read(key)
|
||||
twice = copy.deepcopy(read["문서"])
|
||||
@@ -119,7 +139,7 @@ def test_따로_SK_지금은_줄_옛_기준_새(world):
|
||||
line["수량"] = f"({line.get('수량') or 1}) × 2"
|
||||
saved = path.save(key, {"문서": twice, "판": read["판"]})
|
||||
assert saved["사본"]["따로"] is True
|
||||
old, new = _both(me, _doc(me, key))
|
||||
new = _run(me, _doc(me, key))
|
||||
assert new["수식셈"]["따로"] is True
|
||||
assert _base(new) != _base(old) # 2-C1 에서 뒤집을 단언 — 기준이 옛 길과 다름
|
||||
assert _lines_sum(new) == _base(old) != _base(new) # 2-C1 에서 뒤집을 단언 — 줄 = 옛 길
|
||||
_one_path(new, saved["셈"])
|
||||
assert _base(new) != _base(plain) # 고친 문서 = 새 금액
|
||||
|
||||
@@ -87,21 +87,6 @@ def test_고름_정리_틀리면_400():
|
||||
assert e.value.status == 400
|
||||
|
||||
|
||||
def test_사용자_자재가_로직_자재와_같으면_저장_400():
|
||||
with pytest.raises(store.StoreError) as e:
|
||||
labor.server(_doc(담은로직=[{"로직": NET}], 자재=[{"코드": WIRE}]))
|
||||
assert e.value.status == 400 and WIRE in str(e.value.detail)
|
||||
# 고른 품목도 같음 — 결속선 줄을 다른 품목으로 바꾸면 사용자 자재로 담을 수 있음
|
||||
with pytest.raises(store.StoreError):
|
||||
labor.server(
|
||||
_doc(담은로직=[{"로직": NET, "고름": {"3": "MT000008"}}], 자재=[{"코드": "MT000008"}])
|
||||
)
|
||||
ok = labor.server(
|
||||
_doc(담은로직=[{"로직": NET, "고름": {"4": NET_ITEM}}], 자재=[{"코드": WIRE}])
|
||||
)
|
||||
assert ok["자재"][0]["코드"] == WIRE
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def system(tmp_path, monkeypatch):
|
||||
write_sample_table(tmp_path)
|
||||
@@ -110,15 +95,6 @@ def system(tmp_path, monkeypatch):
|
||||
return tmp_path
|
||||
|
||||
|
||||
def test_저장_뒤_고름_남고_계산값에_반영(system):
|
||||
have = store.read("labor", "rv")
|
||||
sent = {**have["문서"], "담은로직": [{"로직": NET, "고름": {"3": WIRE}, "수량": None}]}
|
||||
store.write("labor", "rv", have["판"], sent)
|
||||
doc = store.read("labor", "rv")["문서"]
|
||||
assert doc["담은로직"][0]["고름"] == {"3": WIRE}
|
||||
assert doc["계산값"]["줄"][0]["재료"][0]["품목"]["키"] == WIRE
|
||||
|
||||
|
||||
def test_단가승격도_고름을_따름_없으면_지금_값():
|
||||
expand = refs.Expand(_whole())
|
||||
plain = expand._promote({"담은로직": [{"로직": NET}], "배": 1})
|
||||
|
||||
Reference in New Issue
Block a user