feat(inout): 옵션 상품 정보 탭 — 단가·무게(PP)·은 함유량, 발주서·메일 금액, 입고 담당 화면 줄이기

- 마이그레이션 004: inout_products(단가·개당 무게 g·은 함유량 %), inout_products_excluded(지운 단품),
  inout_order_lines 에 발주할 때 값 사본(unit_price·weight_g·silver_pct)
- 옵션 → 상품 정보: [단품 불러오기](값을 넣은 상품은 그대로, 지운 단품은 다음에도 빠짐), 바뀐 줄만 저장,
  은 g = 무게 × % 자동, 지우기·되살리기
- 상품 정보가 있으면 발주서 제품은 그 목록에서(단가 함께), 금액 = 수량 × 단가 실시간 합계
- 발주서 화면(발주 담당)·발주 메일에 단가·금액·PP(g/개)·은 함유량과 합계(금액·PP kg·은 g)
- 입고 담당(발주 담당 아님)은 품목을 제품 이름·발주 수량(+ 이번 입고)만, 입고 기록 칩도 이름
- 고침: 그날 100번째 발주서부터 번호가 겹치던 문제(순번 숫자 비교), 시각을 DB 시간대와 무관하게 KST 로 읽음

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 00:59:45 +09:00
parent dcc6cd27b6
commit a475f0b2f6
21 changed files with 1031 additions and 76 deletions
+76 -1
View File
@@ -43,7 +43,7 @@ class InoutDbTests(unittest.TestCase):
def test_partial_receipts_until_done(self):
o = self.order([("MT-A", 100), ("MT-B", 50)])
self.assertRegex(o["order_no"], r"^PO-261016-\d{2}$")
self.assertRegex(o["order_no"], r"^PO-261016-\d{2,}$") # 100번째부터는 세 자리
head = self.st.get_order(o["id"])
self.assertEqual((head["factory_manager"], head["factory_contact"]), ("김공장", "010-1234")) # 담당자·연락처 따로(002)
ids = self.line_ids(o["id"])
@@ -227,5 +227,80 @@ class InoutDbTests(unittest.TestCase):
self.st.delete_gmail_token(me)
self.assertIsNone(self.st.gmail_token(me))
def test_times_are_kst(self):
"""TIMESTAMPTZ 는 한국 시각으로 읽힌다(화면·메일에 찍는 입력·보낸 시각) — DB 서버 시간대와 무관."""
from datetime import timedelta
o = self.order([("MT-K", 1)])
self.assertEqual(self.st.get_order(o["id"])["created_at"].utcoffset(), timedelta(hours=9))
def test_products_import_keep_exclude_snapshot(self):
"""004 — 불러오기(값 있는 상품은 그대로·없는 상품은 새 이름·지운 단품은 건너뜀), 지우기·되살리기, 발주 품목 값 사본.
끝나면 테스트 단품을 지워 상품 정보 목록을 처음 상태로 둔다(다른 테스트는 빈 목록 = 코드표를 가정할 수 있음)."""
from decimal import Decimal as D
from app.modules.inout import store
if not self.st.products_ready():
self.skipTest("inout_db 004 미적용")
T = self.tag.upper()
A, B, C = f"ZT-{T}-A", f"ZT-{T}-B", f"ZT-{T}-C"
items = [{"code": A.lower(), "name": "가"}, {"code": B, "name": "나"}, {"code": C, "name": "다"}]
before = self.st.catalog_count()
try:
r = self.st.import_products(items, by="Boss@Test.local")
self.assertEqual(r["added"], 3)
self.assertEqual(self.st.catalog_count(), before + 3)
self.st.save_products([{"code": A, **store.validate_product_values({"unit_price": "1,500", "weight_g": "24.5",
"silver_pct": "0.5"})}], by="b@x")
with self.assertRaisesRegex(ValueError, "상품 정보에 없는"):
self.st.save_products([{"code": "ZT-NOPE-" + T, "unit_price": None, "weight_g": None, "silver_pct": None}], by="b@x")
# 이름이 바뀌어 다시 불러오기 — A(값 있음)는 그대로, B(값 없음)는 새 이름
r = self.st.import_products([{"code": A, "name": "가2"}, {"code": B, "name": "나2"}, {"code": C, "name": "다"}], by="b@x")
self.assertEqual((r["added"], r["kept"], r["renamed"], r["same"]), (0, 1, 1, 1))
got = self.st.catalog_lookup([A, B])
self.assertEqual((got[A]["item_name"], got[A]["unit_price"]), ("가", D("1500.00")))
self.assertEqual(got[B]["item_name"], "나2")
# 지우기 → 목록·검색에서 빠지고 다음 불러오기에서도 건너뜀 → 되살리기
self.st.exclude_product(C, by="b@x")
self.assertNotIn(C, self.st.catalog_lookup([C]))
self.assertIn(C, [x["item_code"] for x in self.st.list_excluded()])
self.assertEqual(self.st.import_products(items, by="b@x")["excluded"], 1)
self.assertNotIn(C, self.st.catalog_lookup([C]))
self.assertEqual([x["item_code"] for x in self.st.catalog_search(f"ZT-{T}")], [A, B])
self.assertEqual([x["item_code"] for x in self.st.catalog_search("가", limit=500) if x["item_code"].startswith("ZT-" + T)], [A])
self.st.restore_product(C, by="b@x")
self.assertIn(C, self.st.catalog_lookup([C]))
self.assertNotIn(C, [x["item_code"] for x in self.st.list_excluded()])
with self.assertRaises(ValueError):
self.st.restore_product(C, by="b@x")
# 발주 품목 = 발주할 때의 값(사본) — 나중에 단가가 바뀌어도 지난 발주서는 그대로
data = store.validate_order(factory_id=self.fid, order_date="2026-10-16", due_date="", memo="",
codes=[A, B], quantities=["100", "3"])
specs = self.st.catalog_lookup([A, B])
o = self.st.create_order(data, {A: "가", B: "나2"}, by="b@x", specs=specs)
self.st.save_products([{"code": A, **store.validate_product_values({"unit_price": "2000"})}], by="b@x")
lines = {x["item_code"]: x for x in self.st.get_order(o["id"])["lines"]}
self.assertEqual((lines[A]["unit_price"], lines[A]["weight_g"], lines[A]["silver_pct"]), (D("1500.00"), D("24.50"), D("0.5000")))
self.assertIsNone(lines[B]["unit_price"])
t = store.order_totals(list(lines.values()))
self.assertEqual((t["amount"], t["missing_price"], t["silver_g"]), (D("150000.00"), 1, D("12.2500")))
# 고칠 때 새로 넣은 줄만 지금 값, 원래 있던 줄은 사본 그대로
data2 = store.validate_order(factory_id=self.fid, order_date="2026-10-16", due_date="", memo="",
codes=[A, C], quantities=["120", "1"])
self.st.update_order(o["id"], data2, {C: "다"}, by="b@x", specs=self.st.catalog_lookup([C]))
lines = {x["item_code"]: x for x in self.st.get_order(o["id"])["lines"]}
self.assertEqual((lines[A]["qty"], lines[A]["unit_price"]), (120, D("1500.00")))
self.assertEqual(set(lines), {A, C})
finally:
for code in (A, B, C):
try:
self.st.exclude_product(code, by="cleanup@x")
except ValueError:
pass
self.assertEqual(self.st.catalog_count(), before)
if __name__ == "__main__":
unittest.main()