diff --git a/M02_MasterTemplete/M02_Doc_Import.py b/M02_MasterTemplete/M02_Doc_Import.py index d74b21182..de85a7876 100644 --- a/M02_MasterTemplete/M02_Doc_Import.py +++ b/M02_MasterTemplete/M02_Doc_Import.py @@ -570,6 +570,9 @@ def record(doc: dict, sk: dict) -> dict[str, Any]: links.learn(mine) rec.prefetch(mine) dc.mc.calc(mine, rec) + if mine is not doc: # 848-7 엑셀 판 기계 줄 제어 구역 = 연결 문서 · 값도 화면 캐시에 + rec.prefetch(doc) + dc.mc.calc(doc, rec) except Exception: # noqa: BLE001 — 셈 틀림 = 셈 답 표지 · 기록은 모은 데까지 pass return rec.out() diff --git a/common_util/common_util_formula_doc_cover.ts b/common_util/common_util_formula_doc_cover.ts index 23fb406f8..1442c472e 100644 --- a/common_util/common_util_formula_doc_cover.ts +++ b/common_util/common_util_formula_doc_cover.ts @@ -297,7 +297,8 @@ export function pruneWorkLayer( const upForm = upWay === HOURLY ? String(up.식 ?? "") : ""; const form = String(want.식 ?? "") || upForm; if (form !== upForm) out.식 = form; - const held = { ...(base ?? {}), ...(form === upForm ? (up.변수 ?? {}) : {}) }; + const same = form === String(up.식 ?? ""); // 848-7 방식 없는 위 층(가져온 값)도 같은 식이면 변수 물려받음 + const held = { ...(base ?? {}), ...(same ? (up.변수 ?? {}) : {}) }; const got = Object.entries(want.변수 ?? {}).filter( ([k, v]) => v !== null && v !== undefined && v !== "" && !(k in held && sameNum(v, held[k])), ); diff --git a/resources/master_data/scripts/master_doc_cover.py b/resources/master_data/scripts/master_doc_cover.py index 4b0617331..60c27ce37 100644 --- a/resources/master_data/scripts/master_doc_cover.py +++ b/resources/master_data/scripts/master_doc_cover.py @@ -239,7 +239,10 @@ def prune_work_layer(want, base: dict | None = None, upper: dict | None = None) form = str(want.get("식") or "") or up_form if form != up_form: out["식"] = form - held = {**(base or {}), **((up.get("변수") or {}) if form == up_form else {})} + same = form == str( + up.get("식") or "" + ) # 848-7 방식 없는 위 층(가져온 값)도 같은 식이면 변수 물려받음 + held = {**(base or {}), **((up.get("변수") or {}) if same else {})} got = { k: v for k, v in (want.get("변수") or {}).items() diff --git a/resources/tester/test_848_7_import_carry.py b/resources/tester/test_848_7_import_carry.py index aee5ecbed..52b800fe1 100644 --- a/resources/tester/test_848_7_import_carry.py +++ b/resources/tester/test_848_7_import_carry.py @@ -360,3 +360,44 @@ def test_세_줄_OH_나누기_꼴도_한_줄_금액_같음(links): shape.machines(doc, {}, {}) assert len(doc["금액"]) == 1 and doc["금액"][0]["비목곱"] == {"재료비": "0.5"} assert _money(mc.calc(dim.view(doc, "엑셀"), links)) == _money(before) + + +# ── ⑦ 방식 없는 위 층(가져온 값) — 내 고침엔 바꾼 칸만 남음(파이썬 = TS) ───────────── +_JS_PRUNE = r""" +const fs = require("fs"), path = require("path"); +const ts = require(path.join(process.argv[1], "config", "node_modules", "typescript")); +const cache = new Map(); +function load(at) { + if (cache.has(at)) return cache.get(at); + const js = ts.transpileModule(fs.readFileSync(at, "utf8"), { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText; + const box = { exports: {} }; + cache.set(at, box.exports); + const need = (p) => (p.startsWith(".") ? load(path.resolve(path.dirname(at), `${p}.ts`)) : require(p)); + new Function("exports", "module", "require", js)(box.exports, box, need); + return box.exports; +} +const cov = load(path.join(process.argv[1], "common_util", "common_util_formula_doc_cover.ts")); +const xs = JSON.parse(fs.readFileSync(0, "utf8")); +process.stdout.write(JSON.stringify(xs.map((x) => cov.pruneWorkLayer(x[0], x[1], x[2]) ?? null))); +""" + + +def test_방식_없는_위_층_변수_물려받음_거울(): + mcv = importlib.import_module("master_doc_cover") + up = {"식": "GC001155", "변수": {"운반거리": 0.185, "f": 0.85}} + cases = [ + [{"방식": "시간당", "식": "GC001155", "변수": {"운반거리": 0.3, "f": 0.85}}, {}, up], + [{"방식": "시간당", "식": "GC001155", "변수": {"운반거리": 0.185, "f": 0.85}}, {}, up], + [{"방식": "시간당", "식": "GC001173", "변수": {"f": 0.85}}, {}, up], + ] + want = [mcv.prune_work_layer(*c) for c in cases] + assert want == [ + {"방식": "시간당", "식": "GC001155", "변수": {"운반거리": 0.3}}, + {"방식": "시간당", "식": "GC001155"}, # 시간당만 켬 = 경쟁사 값 그대로 + {"방식": "시간당", "식": "GC001173", "변수": {"f": 0.85}}, # 다른 식 = 안 물려받음 + ] + proc = subprocess.run(["node", "-e", _JS_PRUNE, str(ROOT)], input=json.dumps(cases), capture_output=True, + text=True, encoding="utf-8", check=True) # fmt: skip + assert json.loads(proc.stdout) == want