From b7e05f58aa018c7b9ad00bf6fb44135a07f7503f Mon Sep 17 00:00:00 2001 From: king Date: Thu, 5 Nov 2026 14:45:33 +0900 Subject: [PATCH] =?UTF-8?q?feat(=EC=9E=85=EC=B6=9C=EA=B3=A0):=20=EB=B0=9C?= =?UTF-8?q?=EC=A3=BC=20=EB=AA=A9=EB=A1=9D=EC=97=90=20=EC=9E=85=EA=B3=A0?= =?UTF-8?q?=EC=9D=BC=20=EC=97=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 입고 예정일과 발주 사이에 입고일을 보여 준다. 여러 날에 나눠 입고하면 칸 안에서 줄바꿈하고, 같은 날 여러 번 입고는 한 번만, 입고 전에는 - 로 표시한다. Co-Authored-By: Claude Opus 5.5 --- app/modules/inout/CLAUDE.md | 1 + app/modules/inout/db.py | 8 +++++- app/modules/inout/templates/inout/index.html | 5 ++-- tests/js/inout_datepop.browser.test.js | 12 ++++++++ tests/js/render_inout.py | 9 +++++- tests/test_inout_db.py | 30 ++++++++++++++++++++ 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/app/modules/inout/CLAUDE.md b/app/modules/inout/CLAUDE.md index 03f9c85..3a97d26 100644 --- a/app/modules/inout/CLAUDE.md +++ b/app/modules/inout/CLAUDE.md @@ -11,6 +11,7 @@ - 물류 입고를 여러 번 나눠 입력, 품목별 발주·입고·미입고. - 미입고 현황(제품별 합계·발주별·지연). - 발주 목록 상태 보기(진행 중·완료·종결·취소·전체)는 **사람마다 기억**(2026-11-04) — `inout_settings` 키 `list_status:{이메일}`(마이그레이션 없음, 005 미적용이면 기억만 안 함). 주소에 `status` 가 있으면 저장, 없으면 저장값, 그것도 없으면 진행 중. +- 발주 목록 **입고일** 열(2026-11-05, 입고 예정일과 발주 사이, `db.list_orders` `receipt_dates`) — 여러 날에 나눠 입고하면 칸 안에서 줄바꿈(오래된 날부터), 같은 날 여러 번은 한 번만, 입고 전 `-`. - [남은 수량 모두 채우기]를 한 번 더 누르면(= [채운 수량 되돌리기]) 채우기 전 값으로(2026-10-19, `inout.js`). - 초과 입고는 확인 화면 후 허용(트랜잭션 안에서 발주서 잠그고 판단, `confirm_over`). - **전체 입고 완료(모든 품목 입고 ≥ 발주, 상태 done·over)면 더 입고 못 함**(2026-10-19) — 화면은 입고 칸·[입고 저장]·사진·[남은 수량 채우기]를 흐리게 disabled, 서버 `_add_receipt` 도 잠근 뒤 거절. 입고 기록을 지우면 다시 열림. diff --git a/app/modules/inout/db.py b/app/modules/inout/db.py index eec5bb5..a882ceb 100644 --- a/app/modules/inout/db.py +++ b/app/modules/inout/db.py @@ -339,9 +339,15 @@ class InoutDBStore: "SELECT l.order_id, l.item_code, l.item_name, l.qty, COALESCE(sum(rl.qty), 0)::int AS received " "FROM inout_order_lines l LEFT JOIN inout_receipt_lines rl ON rl.order_line_id = l.id " "WHERE l.order_id = ANY(%s) GROUP BY l.id ORDER BY l.line_no", (ids,)).fetchall() if ids else [] + # 입고일 열 — 같은 날 여러 번 입고해도 날짜는 하나 + receipts = conn.execute("SELECT DISTINCT order_id, receipt_date FROM inout_receipts WHERE order_id = ANY(%s) " + "ORDER BY order_id, receipt_date", (ids,)).fetchall() if ids else [] by_order: dict[int, list[dict[str, Any]]] = {} for ln in lines: by_order.setdefault(int(ln["order_id"]), []).append(ln) + receipt_dates: dict[int, list[date]] = {} + for r in receipts: + receipt_dates.setdefault(int(r["order_id"]), []).append(r["receipt_date"]) allowed = store.STATUS_FILTERS.get(status, store.STATUS_FILTERS["active"])[1] out = [] for h in heads: @@ -351,7 +357,7 @@ class InoutDBStore: continue names = [x["item_name"] or x["item_code"] for x in ls] out.append({**h, "status": st, "status_label": store.ORDER_LABELS[st], "summary": store.summarize(ls), - "line_count": len(ls), "items_label": (names[0] + (f" 외 {len(names) - 1}종" if len(names) > 1 else "")) if names else ""}) + "receipt_dates": receipt_dates.get(int(h["id"]), []), "line_count": len(ls), "items_label": (names[0] + (f" 외 {len(names) - 1}종" if len(names) > 1 else "")) if names else ""}) if len(out) >= limit: break return out diff --git a/app/modules/inout/templates/inout/index.html b/app/modules/inout/templates/inout/index.html index 589939d..db9c90e 100644 --- a/app/modules/inout/templates/inout/index.html +++ b/app/modules/inout/templates/inout/index.html @@ -32,7 +32,7 @@
- + {% if perms.super %}{% endif %} @@ -45,6 +45,7 @@ + @@ -61,7 +62,7 @@ {% endif %} {% else %} - + {% endfor %}
발주번호공장제품발주일입고 예정일발주번호공장제품발주일입고 예정일입고일 발주입고미입고진행상태삭제
{{ o.items_label }}
{{ o.line_count }}종
{{ ymd(o.order_date) }} {{ due(o.due_date, today, active) }}{% for d in o.receipt_dates %}
{{ ymd(d) }}
{% else %}-{% endfor %}
{{ n(o.summary.ordered) }} {{ n(o.summary.received) }} {{ n(o.summary.remaining) }}{% if o.summary.over %}
초과 +{{ n(o.summary.over) }}
{% endif %}
{% if filters.status == 'active' %}진행 중인 발주가 없습니다.{% else %}조건에 맞는 발주가 없습니다.{% endif %}
{% if filters.status == 'active' %}진행 중인 발주가 없습니다.{% else %}조건에 맞는 발주가 없습니다.{% endif %}
diff --git a/tests/js/inout_datepop.browser.test.js b/tests/js/inout_datepop.browser.test.js index f8588e5..b1ae52f 100644 --- a/tests/js/inout_datepop.browser.test.js +++ b/tests/js/inout_datepop.browser.test.js @@ -65,6 +65,18 @@ function check(name, cond, extra) { check("필터 줄 높이가 맞음", Math.abs((box.y + box.height / 2) - (search.y + search.height / 2)) < 4, { box: box, search: search }); await p.screenshot({ path: path.join(__dirname, ".out", "inout_list.png") }); + // 목록 입고일 열(2026-11-05) — 입고 예정일과 발주 사이, 여러 날은 한 칸에서 줄바꿈, 입고 전 "-" + const heads = await p.locator(".io-table thead th").allInnerTexts(); + check("입고일 열 위치", heads.indexOf("입고일") === heads.indexOf("입고 예정일") + 1 && heads.indexOf("발주") === heads.indexOf("입고일") + 1, heads); + const col = heads.indexOf("입고일") + 1; + const cell = function (row) { return p.locator(".io-table tbody tr:nth-child(" + row + ") td:nth-child(" + col + ")"); }; + const lines = await cell(1).locator("div").evaluateAll(function (els) { + return els.map(function (el) { return { text: el.textContent, top: el.getBoundingClientRect().top }; }); + }); + check("여러 날 = 줄바꿈", lines.length === 2 && lines[0].text === "2026.10.21(수)" && lines[1].text === "2026.10.23(금)" && lines[1].top > lines[0].top, lines); + check("하루 입고 = 한 줄", (await cell(2).innerText()).trim() === "2026.10.22(목)"); + check("입고 전 = -", (await cell(3).innerText()).trim() === "-"); + await p.goto("http://erp.test/inout_locked.html"); await p.waitForTimeout(200); check("잠긴 입고일은 못 누름", await p.locator('input[name="receipt_date"] + button').isDisabled()); diff --git a/tests/js/render_inout.py b/tests/js/render_inout.py index b3907bd..4053e59 100644 --- a/tests/js/render_inout.py +++ b/tests/js/render_inout.py @@ -20,6 +20,12 @@ OUT_DIR = os.path.join(ROOT, "tests", "js", ".out") from app.modules.inout.router import _date_holidays # noqa: E402 +def _order(no: int, receipt_dates: list[date]) -> dict: + return {"id": no, "order_no": f"PO-26102{no}-01", "factory_name": "대성화학", "items_label": "미라클 봉투", "line_count": 1, + "order_date": date(2026, 10, 20), "due_date": None, "receipt_dates": receipt_dates, "status": "partial", "status_label": "일부 입고", + "summary": {"ordered": 100, "received": 10, "remaining": 90, "over": 0}} + + def main() -> None: os.makedirs(OUT_DIR, exist_ok=True) env = jinja2.Environment( @@ -28,7 +34,8 @@ def main() -> None: base = {"date_holidays": _date_holidays(), "today": date(2026, 10, 5), "user": {"name": "테스트", "email": "t@test.local"}, "nav_items": [], "perms": {"can_order": True, "can_receive": True}} pages = { "inout_form.html": ("inout/order_form.html", {"vals": {"order_date": "2026-10-05", "due_date": ""}, "factories": []}), - "inout_list.html": ("inout/index.html", {"filters": {"from": "2026-10-01", "to": "", "status": "open", "q": "", "factory": ""}, "factories": [], "orders": [], "status_filters": {}}), + "inout_list.html": ("inout/index.html", {"filters": {"from": "2026-10-01", "to": "", "status": "open", "q": "", "factory": ""}, "factories": [], "status_filters": {}, "orders": [ + _order(1, [date(2026, 10, 21), date(2026, 10, 23)]), _order(2, [date(2026, 10, 22)]), _order(3, [])]}), } for out, (name, ctx) in pages.items(): with open(os.path.join(OUT_DIR, out), "w", encoding="utf-8") as f: diff --git a/tests/test_inout_db.py b/tests/test_inout_db.py index 0a8c7b5..5bc3b36 100644 --- a/tests/test_inout_db.py +++ b/tests/test_inout_db.py @@ -15,6 +15,26 @@ DSN = os.getenv("INOUT_TEST_DB_URL", "") ENABLED = bool(DSN) and urlparse(DSN).hostname in ("localhost", "127.0.0.1") +class ListReceiptDatesNoDbTests(unittest.TestCase): + """DB 없이 — 발주별로 입고일을 묶어 돌려주는지(입고 없는 발주 = 빈 목록).""" + + def test_groups_dates_by_order(self): + from contextlib import nullcontext + from unittest.mock import MagicMock + + from app.modules.inout.db import InoutDBStore + + heads = [{"id": i, "order_no": f"PO-{i}", "closed_at": None, "cancelled_at": None} for i in (1, 2)] + lines = [{"order_id": i, "item_code": "A", "item_name": "A", "qty": 10, "received": 1} for i in (1, 2)] + receipts = [{"order_id": 1, "receipt_date": date(2026, 10, 21)}, {"order_id": 1, "receipt_date": date(2026, 10, 23)}] + conn = MagicMock() + conn.execute.side_effect = lambda sql, *a: MagicMock(fetchall=lambda: receipts if "receipt_date" in sql else lines if "inout_order_lines l" in sql else heads) + st = InoutDBStore.__new__(InoutDBStore) + st._pool = MagicMock(connection=lambda: nullcontext(conn)) + got = {o["id"]: o["receipt_dates"] for o in st.list_orders()} + self.assertEqual(got, {1: [date(2026, 10, 21), date(2026, 10, 23)], 2: []}) + + @unittest.skipUnless(ENABLED, "INOUT_TEST_DB_URL(localhost) not set") class InoutDbTests(unittest.TestCase): @classmethod @@ -66,6 +86,16 @@ class InoutDbTests(unittest.TestCase): self.assertNotIn(o["id"], [x["id"] for x in self.st.list_orders(status="active", factory_id=self.fid)]) self.assertIn(o["id"], [x["id"] for x in self.st.list_orders(status="done", factory_id=self.fid)]) + def test_list_receipt_dates(self): + """목록 입고일 — 입고 전 빈 목록, 여러 날은 오래된 날부터, 같은 날 두 번은 한 번만.""" + o = self.order([("MT-D", 100)]) + line = self.line_ids(o["id"])["MT-D"] + dates = lambda: next(x for x in self.st.list_orders(status="all", factory_id=self.fid) if x["id"] == o["id"])["receipt_dates"] + self.assertEqual(dates(), []) + for day in ("2026-10-23", "2026-10-21", "2026-10-23"): + self.st.add_receipt(o["id"], {line: "10"}, receipt_date=day, memo="", confirm_over=False, by="w@x") + self.assertEqual(dates(), [date(2026, 10, 21), date(2026, 10, 23)]) + def test_over_receipt_needs_confirm(self): from app.modules.inout.db import OverReceipt