Merge remote-tracking branch 'origin/sub_laptop_1' into main_laptop_1

This commit is contained in:
2026-09-24 10:28:18 +09:00
3 changed files with 25 additions and 0 deletions
+2
View File
@@ -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("입력", []):
+13
View File
@@ -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("까닭")} == {"체인오일", "체인톱 손료"}