feat(inout): 전체 입고 완료면 입고 저장 막기 · 사방넷 입고 파일 버튼 엑셀 초록

- 모든 품목 입고 완료·초과면 입고 칸·[입고 저장] 등 흐리게 disabled, 서버도 잠근 뒤 거절
- 사방넷 입고 파일 버튼 #217346

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 14:03:54 +09:00
parent 2237e2e799
commit 90af8a8486
9 changed files with 41 additions and 15 deletions
+2 -1
View File
@@ -11,6 +11,7 @@
- 물류 입고를 여러 번 나눠 입력, 품목별 발주·입고·미입고.
- 미입고 현황(제품별 합계·발주별·지연).
- 초과 입고는 확인 화면 후 허용(트랜잭션 안에서 발주서 잠그고 판단, `confirm_over`).
- **전체 입고 완료(모든 품목 입고 ≥ 발주, 상태 done·over)면 더 입고 못 함**(2026-10-19) — 화면은 입고 칸·[입고 저장]·사진·[남은 수량 채우기]를 흐리게 disabled, 서버 `_add_receipt` 도 잠근 뒤 거절. 입고 기록을 지우면 다시 열림.
- 잔량 종결·취소(취소는 입고 없을 때만).
- 상태는 저장하지 않고 누적 입고로 계산(`store.order_status`).
- 모든 품목 입고완료·초과입고 = "✓ 전체 입고 완료"(초과면 "초과 포함", `order_badge`).
@@ -38,7 +39,7 @@
## 사방넷 입고 파일 (2026-10-19, 마이그레이션 없음)
- 입고 기록 줄 [사방넷 입고 파일] → `GET /inout/orders/{id}/receipts/{rid}/sabangnet.xlsx`(발주·입고 담당). 1행 제목 **A 상품코드 · B 가용수량 · C 불용수량**,
- 입고 기록 줄 [사방넷 입고 파일](엑셀 초록 `#217346`) → `GET /inout/orders/{id}/receipts/{rid}/sabangnet.xlsx`(발주·입고 담당). 1행 제목 **A 상품코드 · B 가용수량 · C 불용수량**,
A = 코드표 `single_items.sabangnet_code`(`itemcode.sabangnet_codes`), B = 입고 수량, **C = 수량이 아니라 상품 이름**(사용자 지정). A·C 는 글자 칸(앞자리 0 보존).
- 사방넷 코드가 빈 품목이 있거나 코드표를 못 읽으면 파일을 만들지 않고 발주서로 돌아가 품목을 알려 준다(빈 칸 업로드 방지). 파일 이름 `사방넷_입고_{입고일}_{발주번호}.xlsx`.
+3
View File
@@ -354,6 +354,9 @@ class InoutDBStore:
"SELECT l.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=%s GROUP BY l.id", (order_id,)).fetchall()
# 전체 입고 완료(모든 품목 입고 ≥ 발주)면 더 받지 않는다(2026-10-19) — 화면은 버튼을 막고, 서버도 거절(잠근 뒤 판단)
if lines and all(int(x["received"]) >= int(x["qty"]) for x in lines):
raise ValueError("전체 입고가 완료된 발주서입니다 — 더 입고할 수 없습니다(잘못 넣은 입고는 입고 기록에서 지운 뒤 다시 넣으세요).")
data = store.validate_receipt(lines, quantities, receipt_date=receipt_date, memo=memo)
if data["over"] and not confirm_over:
raise OverReceipt(data["over"])
+1 -1
View File
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
{% from "inout/_macros.html" import order_badge, progress, due, n, ymd %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019b" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019c" />{% endblock %}
{% block content %}
<section class="io">
@@ -20,11 +20,14 @@
</footer>
</dialog>
{%- endmacro -%}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019b" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019c" />{% endblock %}
{% block content %}
{% set active = order.status in ('open', 'partial') %}
{% set receiving = perms.can_receive and can_receive_now %}
{# 전체 입고 완료(모든 품목 입고완료·초과) — 입고 칸·[입고 저장]을 흐리게 막는다(서버도 거절, 2026-10-19). 입고 기록을 지우면 다시 열림 #}
{% set recv_done = order.status in ('done', 'over') %}
{% set dis = ' disabled' if recv_done else '' %}
{% set photo_admin = perms.can_receive and not order.cancelled_at %}
<section class="io">
{% include "inout/_nav.html" %}
@@ -79,11 +82,12 @@
<form method="post" action="/inout/orders/{{ order.id }}/receipts" class="erp-card-block io-block" id="io-receipt-form" enctype="multipart/form-data">
{# Enter 키 = 이 버튼(일반 저장). 없으면 폼의 첫 제출 버튼인 [초과 입고로 저장]이 눌려 확인 없이 초과가 저장된다 #}
{% if receiving %}<button type="submit" class="io-default-submit" tabindex="-1" aria-hidden="true">입고 저장</button>{% endif %}
{% if receiving %}<button type="submit" class="io-default-submit" tabindex="-1" aria-hidden="true"{{ dis }}>입고 저장</button>{% endif %}
<input type="hidden" name="confirm_over" value="" id="io-confirm-over" />
<div class="erp-card-block-head">
<h2>품목</h2>
{% if receiving %}<span class="erp-muted">물류에 들어온 수량을 [이번 입고]에 넣고 저장 — 여러 번 나눠 넣어도 됩니다</span>
{% if receiving and recv_done %}<span class="erp-muted io-recv-done-note">✓ 전체 입고 완료 — 더 입고할 수 없습니다(잘못 넣은 입고는 아래 입고 기록에서 지운 뒤 다시 넣으세요)</span>
{% elif receiving %}<span class="erp-muted">물류에 들어온 수량을 [이번 입고]에 넣고 저장 — 여러 번 나눠 넣어도 됩니다</span>
{% elif perms.can_receive and order.closed_at %}<span class="erp-muted">종결된 발주서 — 입고하려면 발주 담당이 종결을 풀어야 합니다</span>{% endif %}
</div>
@@ -128,7 +132,7 @@
{% if receiving %}<td class="io-col-recv"><input class="erp-input io-qty io-recv" type="text" inputmode="numeric" name="qty_{{ ln.id }}"
value="{{ receipt_form.qty.get(ln.id, '') }}" data-remaining="{{ ln.remaining }}" data-ordered="{{ ln.qty }}" data-received="{{ ln.received }}"
data-code="{{ ln.item_code }}" data-name="{{ ln.item_name }}" placeholder="{{ ln.remaining if ln.remaining and not items_limited else '' }}"
aria-label="{{ ln.item_name }} 이번 입고 수량" /></td>{% endif %}
aria-label="{{ ln.item_name }} 이번 입고 수량"{{ dis }} /></td>{% endif %}
</tr>
{% endfor %}
</tbody>
@@ -147,19 +151,19 @@
</table>
</div>
{% if receiving %}
<div class="io-receipt-bar">
<label class="erp-field"><span>입고일 *</span><input type="date" name="receipt_date" value="{{ receipt_form.receipt_date }}" required /></label>
<label class="erp-field io-grow"><span>메모</span><input type="text" name="memo" value="{{ receipt_form.memo }}" maxlength="500" placeholder="차량·박스 수·검수 메모 등" /></label>
<div class="io-receipt-bar{% if recv_done %} is-locked{% endif %}"{% if recv_done %} aria-disabled="true" title="전체 입고 완료 — 더 입고할 수 없습니다"{% endif %}>
<label class="erp-field"><span>입고일 *</span><input type="date" name="receipt_date" value="{{ receipt_form.receipt_date }}" required{{ dis }} /></label>
<label class="erp-field io-grow"><span>메모</span><input type="text" name="memo" value="{{ receipt_form.memo }}" maxlength="500" placeholder="차량·박스 수·검수 메모 등"{{ dis }} /></label>
<div class="erp-field io-photo-field">
<span>입고증 사진 <small>(최대 {{ max_photos }}장)</small></span>
<label class="io-photo-pick">
<input type="file" name="photos" accept="image/*" multiple id="io-photo-input" class="io-photo-input" data-max="{{ max_photos }}" />
<input type="file" name="photos" accept="image/*" multiple id="io-photo-input" class="io-photo-input" data-max="{{ max_photos }}"{{ dis }} />
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 8h3l2-3h6l2 3h3v11H4z"/><circle cx="12" cy="13" r="3.5"/></svg>
사진 고르기·찍기
</label>
</div>
<button type="button" class="erp-btn erp-btn-outline" id="io-fill-remaining">남은 수량 모두 채우기</button>
<button type="submit" class="erp-btn erp-btn-primary">입고 저장 <span id="io-recv-total"></span></button>
<button type="button" class="erp-btn erp-btn-outline" id="io-fill-remaining"{{ dis }}>남은 수량 모두 채우기</button>
<button type="submit" class="erp-btn erp-btn-primary io-recv-save"{{ dis }}>입고 저장 <span id="io-recv-total"></span></button>
<div class="io-photo-previews" id="io-photo-previews" aria-live="polite"></div>
</div>
{% endif %}
@@ -1,5 +1,5 @@
{% extends "erp_base.html" %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019b" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019c" />{% endblock %}
{% block content %}
<section class="io">
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
{% from "inout/_macros.html" import due, n, ymd %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019b" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019c" />{% endblock %}
{% block content %}
<section class="io">
+10
View File
@@ -295,3 +295,13 @@
.io-logi-field > span { font-weight: 600; }
.io-logi-field small { font-weight: 400; color: var(--color-midtone-gray, #777); }
.io-rmail-cell .io-sabang-btn { margin-top: 4px; display: inline-flex; }
/* 사방넷 입고 파일 버튼 — 엑셀 초록(2026-10-19) */
.io .erp-btn.io-sabang-btn { background: #217346; border-color: #217346; color: #fff; }
.io .erp-btn.io-sabang-btn:hover, .io .erp-btn.io-sabang-btn:focus-visible { background: #185c37; border-color: #185c37; color: #fff; }
/* 전체 입고 완료 — 입고 칸·버튼 흐리게, 누를 수 없게 */
.io-receipt-bar.is-locked { opacity: .5; }
.io-receipt-bar.is-locked .erp-btn, .io-receipt-bar.is-locked .io-photo-pick, .io-receipt-bar.is-locked input { cursor: not-allowed; pointer-events: none; }
.io-table .io-recv:disabled { opacity: .5; cursor: not-allowed; background: #f3f4f6; }
.io-recv-done-note { color: #1e7a34; font-weight: 600; }
+5 -1
View File
@@ -31,6 +31,10 @@
- **초과 입고**: 입고 저장 때 발주를 넘는 품목이 있으면 저장하지 않고 확인 화면(409, 넣은 숫자 유지) → [초과 입고로 저장](`confirm_over=1`).
판단은 DB 트랜잭션 안에서 발주서 행을 잠그고(`FOR UPDATE`) 누적 입고를 다시 읽어 한다 — 동시에 입고해도 확인을 건너뛰지 않음.
Enter 키는 숨은 기본 버튼(일반 저장)으로 가게 해 확인 없이 초과가 저장되지 않게 했다.
- **전체 입고 완료 뒤 입고 막기**(2026-10-19 요청): 모든 품목이 입고완료·초과(발주서 done·over)면 품목 머리에 "✓ 전체 입고 완료 — 더 입고할 수 없습니다",
이번 입고 칸·입고일·메모·사진·[남은 수량 모두 채우기]·[입고 저장]·숨은 기본 버튼을 `disabled` + 흐리게(`.io-receipt-bar.is-locked`).
서버도 `_add_receipt` 에서 발주서를 잠근 뒤 모든 품목 누적 입고 ≥ 발주면 ValueError(초과 확인을 해도) — 두 창에서 동시에 넣어도 막힘.
잘못 넣은 입고는 입고 기록에서 지우면 다시 입고할 수 있다. 입고 기록의 사진 더하기·입고 요청 메일·사방넷 파일은 그대로.
- 발주서 고치기: 입고된 품목은 **뺄 수 없다**(입고 기록이 사라지므로) — 수량은 바꿀 수 있다(입고보다 줄이면 초과로 보임).
- 입고 기록 지우기(입고 담당): 잘못 넣은 1건을 지우면 그만큼 다시 미입고.
- 발주번호: `PO-YYMMDD-NN`(발주일 기준 그날 순번, advisory lock 으로 동시 생성해도 겹치지 않음). 순번은 숫자로 비교한다 — 100번째부터 세 자리(`-100`).
@@ -184,7 +188,7 @@ cupang·malaysia 와 같은 DSN). 화면에서 코드·이름으로 검색(`GET
## 6-5. 사방넷 입고 파일(2026-10-19, 마이그레이션 없음)
- 입고 기록 표 **입고 요청 메일 · 사방넷** 칸의 **[사방넷 입고 파일]**(발주 담당·입고 담당) → 그 입고 1건의 엑셀(`GET …/receipts/{rid}/sabangnet.xlsx`).
- 입고 기록 표 **입고 요청 메일 · 사방넷** 칸의 **[사방넷 입고 파일]**(엑셀 초록 버튼, 발주 담당·입고 담당) → 그 입고 1건의 엑셀(`GET …/receipts/{rid}/sabangnet.xlsx`).
- 시트 1행 = 제목 **상품코드 · 가용수량 · 불용수량**(굵게·회색 바탕), 2행부터 입고 품목마다
A = 코드표(itemcode_db `single_items.sabangnet_code`, `itemcode.SingleItemReader.sabangnet_codes`) 사방넷 코드,
B = 입고 수량, **C = 상품 이름**(사용자 요청 — 불용수량 칸이지만 수량이 아니라 이름). A·C 는 글자 서식(`@`, 앞자리 0 보존), 열 너비는 내용 길이로.
+4
View File
@@ -57,6 +57,10 @@ class InoutDbTests(unittest.TestCase):
confirm_over=False, by="w@x")
got = self.st.get_order(o["id"])
self.assertEqual((got["status"], got["summary"]["remaining"], len(got["receipts"])), ("done", 0, 2))
# 전체 입고 완료 뒤엔 더 받지 않는다(2026-10-19) — 초과 확인을 해도
with self.assertRaisesRegex(ValueError, "전체 입고가 완료"):
self.st.add_receipt(o["id"], {ids["MT-A"]: "1"}, receipt_date="2026-10-23", memo="", confirm_over=True, by="w@x")
self.assertEqual(len(self.st.get_order(o["id"])["receipts"]), 2)
self.assertEqual([r["total"] for r in got["receipts"]], [60, 90])
# 진행 중 목록에서 빠지고 완료 목록에
self.assertNotIn(o["id"], [x["id"] for x in self.st.list_orders(status="active", factory_id=self.fid)])