diff --git a/app/modules/inout/CLAUDE.md b/app/modules/inout/CLAUDE.md index 5b82942..11bf26f 100644 --- a/app/modules/inout/CLAUDE.md +++ b/app/modules/inout/CLAUDE.md @@ -94,6 +94,12 @@ - 화면 계산만 — 발주 품목 사본·발주서 화면·**발주 메일에는 넣지 않음**(사용자 지정). 값은 지금 상품 정보(`_form_page` 의 `body_per_box`, `/api/items`). - 007 확인 `db.boxes_ready`(groups_ready 와 같은 방식 — 연결 열기 전, 미적용 1분 기억). 그룹·색상 조회(`_PRODUCT_SELECT_006`)는 `p.*` 라 새 열이 따라온다. +## 봉투·백 (008, 2026-11-04) + +- 이름에 **"미라클 봉투"·"미라클백"** 이 들어간 상품(`store.is_bag`, 저장 안 함 — 이름으로 판단) = 옵션 → 상품 정보에서 일반 상품과 **표를 나눔**(봉투·백 표가 위). 박스 칸만 다름: **박스당 수량**(`body_per_box` 재사용)·**1파렛트당 박스 수량**(`inout_products.boxes_per_pallet`). 뚜껑 없음(저장하면 `lid_per_box` 는 NULL). +- 새 발주서 합계 줄에 봉투·백 박스·파렛트를 **통·뚜껑과 따로** 표시: 파렛트 = ⌈Σ(박스 ÷ 그 상품 1파렛트 박스)⌉, 그림 없음. 입수·1파렛트 값은 `store.box_info`(`_form_page`·`/api/items`). +- 008 확인 `db.bags_ready`(boxes_ready 와 같은 방식). 미적용이면 모두 일반 상품으로 동작. + ## 오른쪽 달력 (2026-10-21) - 입출고 **모든 화면** 2열(`.io-split` = 왼쪽 `section.io` | 오른쪽 `_calendar.html`, 1100px 미만은 한 열 300px). 스크롤해도 위에 붙음. diff --git a/app/modules/inout/db.py b/app/modules/inout/db.py index 5c00c09..eec5bb5 100644 --- a/app/modules/inout/db.py +++ b/app/modules/inout/db.py @@ -637,7 +637,12 @@ class InoutDBStore: self._need_products() grouped = self.groups_ready() and any("group_id" in r for r in rows) boxed = self.boxes_ready() and any("body_per_box" in r for r in rows) + bagged = self.bags_ready() and any("boxes_per_pallet" in r for r in rows) with self._pool.connection() as conn, conn.transaction(): + if bagged: # 008 — 봉투·백 1파렛트당 박스 수량 + for r in rows: + if "boxes_per_pallet" in r: + conn.execute("UPDATE inout_products SET boxes_per_pallet=%s WHERE item_code=%s", (r["boxes_per_pallet"], r["code"])) if boxed: # 007 — 통·뚜껑 박스 입수(그룹과 무관, 상품마다) for r in rows: if "body_per_box" in r: @@ -759,6 +764,22 @@ class InoutDBStore: self._boxes_checked = time.monotonic() return ok + def bags_ready(self) -> bool: + """008 이 적용됐나(상품 boxes_per_pallet). boxes_ready 와 같은 방식.""" + if getattr(self, "_bags_ok", False): + return True + if time.monotonic() - getattr(self, "_bags_checked", -1e9) < 60: + return False + if not self.products_ready(): + return False + with self._pool.connection() as conn: + ok = bool(conn.execute( + "SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'inout_products' " + "AND column_name = 'boxes_per_pallet') AS ok").fetchone()["ok"]) + self._bags_ok = ok + self._bags_checked = time.monotonic() + return ok + def _need_groups(self) -> None: if not self.groups_ready(): raise ValueError("DB 마이그레이션 inout_db 006(상품 그룹·색상)이 아직 적용되지 않았습니다.") diff --git a/app/modules/inout/router.py b/app/modules/inout/router.py index 19f56e1..f341450 100644 --- a/app/modules/inout/router.py +++ b/app/modules/inout/router.py @@ -267,7 +267,7 @@ def _form_page(request: Request, user: dict[str, Any], st: Any, *, order: dict[s ln["price"] = float(price) if price is not None else None ln["price_label"] = store.fmt_num(price) if price is not None else "" bx = boxes.get(ln["code"]) or {} # 박스 입수(007) — 지금 상품 정보 값(발주 품목에 남기지 않음) - ln["body_per_box"], ln["lid_per_box"] = bx.get("body_per_box"), bx.get("lid_per_box") + ln.update(store.box_info(bx)) reader = _items(request) catalog_n = st.catalog_count() return _render(request, "inout/order_form.html", user, { @@ -939,8 +939,10 @@ def _options_ctx(request: Request, st: Any) -> dict[str, Any]: known.add(e) reader = _items(request) products = st.list_products() + bags_ready = st.bags_ready() for pr in products: pr["silver_g"] = store.silver_g(pr.get("weight_g"), pr.get("silver_pct")) + pr["is_bag"] = bags_ready and store.is_bag(pr.get("item_name")) return {"products": products, "excluded": st.list_excluded(), "products_ready": st.products_ready(), "groups": st.list_groups(), "groups_ready": st.groups_ready(), "colors": store.COLORS, "boxes_ready": st.boxes_ready(), @@ -1099,7 +1101,9 @@ def settings_products_save(request: Request, payload: dict[str, Any] = Body(...) code = str((r or {}).get("code") or "").strip().upper() try: row = {"code": code, **store.validate_product_values(r)} - if "body_per_box" in (r or {}): # 007 — 통·뚜껑 박스 입수(빈칸 = 없음) + if "boxes_per_pallet" in (r or {}): # 008 — 봉투·백(박스당 수량·1파렛트당 박스 수량) + row.update(store.validate_bag_values(r)) + elif "body_per_box" in (r or {}): # 007 — 통·뚜껑 박스 입수(빈칸 = 없음) row.update(store.validate_box_values(r)) if "group_id" in (r or {}): # 006 — 그룹(빈칸 = 그룹 없음)·상품 자기 색상 gid = str(r.get("group_id") or "").strip() @@ -1198,7 +1202,7 @@ def api_items(request: Request, q: str = "") -> JSONResponse: "weight_g": store.fmt_num(r["weight_g"]) if r["weight_g"] is not None else "", "silver_pct": store.fmt_num(r["silver_pct"], 4) if r["silver_pct"] is not None else "", "color": r.get("color") or "none", - "body_per_box": r.get("body_per_box"), "lid_per_box": r.get("lid_per_box")} for r in rows]}) + **store.box_info(r)} for r in rows]}) reader = _items(request) if reader is None or not reader.enabled: return JSONResponse({"items": [], "enabled": False, diff --git a/app/modules/inout/store.py b/app/modules/inout/store.py index 54c33c9..5fd1842 100644 --- a/app/modules/inout/store.py +++ b/app/modules/inout/store.py @@ -586,7 +586,8 @@ def validate_product_values(values: dict[str, Any]) -> dict[str, Decimal | None] def has_values(p: dict[str, Any]) -> bool: """단가·무게·은 함유량(·그룹·색상 006·박스 입수 007) 중 하나라도 넣었나 — 넣은 상품은 다시 불러와도 그대로 둔다.""" return (any(p.get(k) is not None for k in PRODUCT_LIMITS) or p.get("group_id") is not None - or (p.get("color") or "none") != "none" or any(p.get(k) is not None for k in BOX_FIELDS)) + or (p.get("color") or "none") != "none" or any(p.get(k) is not None for k in BOX_FIELDS) + or p.get("boxes_per_pallet") is not None) # ════════════════════════════════════════════════════════════ @@ -598,9 +599,9 @@ MAX_PER_BOX = 1_000_000 PALLET_BOXES = 30 -def parse_per_box(raw: Any, *, key: str) -> int | None: +def parse_per_box(raw: Any, *, key: str = "", label: str = "") -> int | None: """박스 입수 칸 하나 — 빈칸은 None(없음·미입력), 1 이상 정수(쉼표 허용).""" - label = BOX_FIELDS[key] + label = label or BOX_FIELDS[key] s = str(raw if raw is not None else "").replace(",", "").strip() if not s: return None @@ -608,7 +609,7 @@ def parse_per_box(raw: Any, *, key: str) -> int | None: raise ValueError(f"{label}은(는) 1 이상 정수로 입력하세요.") n = int(s) if n < 1: - raise ValueError(f"{label}은(는) 1 이상이어야 합니다(뚜껑이 없으면 빈칸).") + raise ValueError(f"{label}은(는) 1 이상이어야 합니다(없으면 빈칸).") if n > MAX_PER_BOX: raise ValueError(f"{label}이(가) 너무 큽니다.") return n @@ -618,6 +619,26 @@ def validate_box_values(values: dict[str, Any]) -> dict[str, int | None]: return {k: parse_per_box(values.get(k), key=k) for k in BOX_FIELDS} +# 봉투·백(2026-11-04, 마이그레이션 008) — 이름으로 판단(저장 안 함). 뚜껑 없음, 박스당 수량 = body_per_box, 1파렛트 박스 수는 상품마다. +BAG_NAME_WORDS = ("미라클 봉투", "미라클백") + + +def is_bag(name: Any) -> bool: + return any(word in str(name or "") for word in BAG_NAME_WORDS) + + +def validate_bag_values(values: dict[str, Any]) -> dict[str, int | None]: + return {"body_per_box": parse_per_box(values.get("body_per_box"), label="박스당 수량"), "lid_per_box": None, + "boxes_per_pallet": parse_per_box(values.get("boxes_per_pallet"), label="1파렛트당 박스 수량")} + + +def box_info(row: dict[str, Any]) -> dict[str, Any]: + """발주서 화면 박스 계산 값 — 008 미적용(열 없음)이면 모두 일반 상품으로.""" + bag = "boxes_per_pallet" in row and is_bag(row.get("item_name")) + return {"body_per_box": row.get("body_per_box"), "lid_per_box": None if bag else row.get("lid_per_box"), + "is_bag": bag, "boxes_per_pallet": row.get("boxes_per_pallet") if bag else None} + + # ════════════════════════════════════════════════════════════ # 상품 그룹·색상(2026-10-21, 마이그레이션 006) # 그룹에 은 함유량·색상을 한 번만 — 그룹 상품은 그룹 값, 그룹 없는 상품은 자기 값(effective_product). diff --git a/app/modules/inout/templates/inout/_options_panel.html b/app/modules/inout/templates/inout/_options_panel.html index 725bc40..bac5eba 100644 --- a/app/modules/inout/templates/inout/_options_panel.html +++ b/app/modules/inout/templates/inout/_options_panel.html @@ -141,6 +141,7 @@ 값을 넣은 상품은 다시 불러와도 그대로이고, 지운 단품은 다음 불러오기에서 빠집니다. 발주서 제품은 이 목록에서 고르며, 발주할 때의 값이 발주서에 남습니다. {% if groups_ready %}그룹을 고른 상품은 은 함유량·색상을 그룹 값으로 씁니다(상품 그룹 탭에서 한 번만 설정).{% endif %} {% if boxes_ready %}통 수량(박스)·뚜껑 수량(박스) = 통·뚜껑이 한 박스에 몇 개씩 들어가는지(뚜껑이 없으면 빈칸) — 새 발주서에서 박스 수·파렛트 수를 계산합니다.{% endif %} + 이름에 "미라클 봉투"·"미라클백"이 들어간 상품은 봉투·백 표에서 박스당 수량·1파렛트당 박스 수량을 넣습니다.
{% if products %}| 코드 | 제품명 | {% if groups_ready %}그룹 | {% endif %}단가(원) | 무게·PP(g/개) | 은 함유량(%) | 은(g/개) | {% if boxes_ready %}통 수량(박스) | 뚜껑 수량(박스) | {% endif %}{% if groups_ready %}색상 | {% endif %}|||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 코드 | 제품명 | {% if groups_ready %}그룹 | {% endif %}단가(원) | 무게·PP(g/개) | 은 함유량(%) | 은(g/개) | {% if bag_table %}박스당 수량 | 1파렛트당 박스 수량 | {% elif boxes_ready %}통 수량(박스) | 뚜껑 수량(박스) | {% endif %}{% if groups_ready %}색상 | {% endif %}|
| {{ p.item_code }} | @@ -171,7 +177,10 @@{% if groups_ready %}{{ fmt_num(p.silver_pct, 4) if p.silver_pct is not none else '-' }}{% endif %} | {{ fmt_num(p.silver_g, 4) if p.silver_g is not none else '-' }} | - {% if boxes_ready %} + {% if bag_table %} ++ | + {% elif boxes_ready %} | {% endif %} @@ -186,6 +195,8 @@ {% endfor %} |
아직 불러온 단품이 없습니다 — [단품 불러오기]를 누르세요. (그 전에는 발주서에서 코드표 단품을 바로 고릅니다)
diff --git a/app/modules/inout/templates/inout/index.html b/app/modules/inout/templates/inout/index.html index ec20dc1..7ad51fe 100644 --- a/app/modules/inout/templates/inout/index.html +++ b/app/modules/inout/templates/inout/index.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} {% from "inout/_macros.html" import order_badge, progress, due, n, ymd %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}