fix(M01): 빠진 원 단위 입력도 null 처럼 그 줄만 비움 (/calc · /text)
- mf.fill_empty — 화면이 안 보낸 가격 입력(단위에 원)을 null 로 채움 · Store.calc·text 에서 부름 - 시험 test_m01_auto.py 한 개 더 — 입력 둘 뺀 GF000056 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JgUhN55Z3BCYhUJTjwTNfj
This commit is contained in:
@@ -548,6 +548,7 @@ def calc(key: str, inputs: dict, row: dict | None = None, file: str | None = Non
|
||||
if row is not None:
|
||||
key = _swap(files, str(row.get("키") or key), row, file)
|
||||
try:
|
||||
given = cm.mf.fill_empty(cm.mf.Master(files).logic(key), given)
|
||||
result = cm.calc(files, key, given)
|
||||
except (cm.mf.FormulaError, ArithmeticError, KeyError, TypeError, ValueError) as e:
|
||||
return {"ok": False, "reason": str(e) or type(e).__name__}
|
||||
@@ -577,6 +578,7 @@ def text(key: str, inputs: dict, row: dict | None = None, file: str | None = Non
|
||||
if row is not None:
|
||||
key = _swap(files, str(row.get("키") or key), row, file)
|
||||
try:
|
||||
given = cm.mf.fill_empty(cm.mf.Master(files).logic(key), given)
|
||||
return mtx.lines(files, key, given)
|
||||
except (cm.mf.FormulaError, ArithmeticError, KeyError, TypeError, ValueError) as e:
|
||||
return {"ok": False, "reason": str(e) or type(e).__name__}
|
||||
|
||||
@@ -449,6 +449,16 @@ def cut(row: dict, value: Decimal, on: str) -> Decimal:
|
||||
return _round(value, rule.get("자리") or 0, way)
|
||||
|
||||
|
||||
def fill_empty(row: dict, given: dict) -> dict:
|
||||
"""화면이 안 보낸 가격 입력(단위에 「원」)은 null 로 채움 — 빈 입력과 같이 그 줄만 비움."""
|
||||
gap = {
|
||||
s["이름"]: None
|
||||
for s in row.get("입력", [])
|
||||
if s["이름"] not in given and "원" in str(s.get("단위") or "")
|
||||
}
|
||||
return {**given, **gap}
|
||||
|
||||
|
||||
def _inputs(row: dict, given: dict) -> dict:
|
||||
env = {}
|
||||
for spec in row.get("입력", []):
|
||||
|
||||
@@ -111,3 +111,16 @@ def test_빈_입력을_쓰는_줄만_비움(client) -> None:
|
||||
rest = sum(Decimal(str(one["금액"])) for one in got["lines"] if one["금액"] is not None)
|
||||
assert Decimal(str(got["sums"]["계"])) == rest > 0 # 빈 줄은 빼고 더함
|
||||
assert got["sums"]["경비"] == 0
|
||||
|
||||
|
||||
def test_빠진_원_입력도_null_처럼_줄만_비움(client) -> None:
|
||||
given = {
|
||||
k: v
|
||||
for k, v in _auto(client, "GF000056").items()
|
||||
if k not in ("체인톱가격", "체인오일단가")
|
||||
}
|
||||
for path in ("calc", "text"):
|
||||
got = client.post(f"/api/m01/{path}", json={"key": "GF000056", "inputs": given}).json()
|
||||
assert got["ok"] is True, (path, got)
|
||||
lines = client.post("/api/m01/calc", json={"key": "GF000056", "inputs": given}).json()["lines"]
|
||||
assert {o["이름"] for o in lines if o.get("까닭")} == {"체인오일", "체인톱 손료"}
|
||||
|
||||
Reference in New Issue
Block a user