## 구현 내용 ### 1. 백엔드 (app.py) - 수동 로트 배분 지원 (lot_assignments 배열 처리) - 각 로트별 지정 수량만큼 재고 차감 - 검증: 배분 합계 확인, 재고 충분 확인 - compound_consumptions 테이블에 각 로트별 소비 기록 ### 2. 프론트엔드 (app.js, index.html) - 로트 배분 모달 UI 구현 - 로트별 재고, 단가 표시 - 수동 입력 및 자동 배분 기능 - 실시간 합계 계산 및 검증 - 원산지 선택에 "수동 배분" 옵션 추가 (로트 2개 이상 시) - 조제 저장 시 lot_assignments 포함 ### 3. 테스트 - 테스트용 당귀 로트 추가 (한국산) - E2E 테스트 성공 - 당귀 100g을 2개 로트(중국산 60g + 한국산 40g)로 배분 - 각 로트별 재고 정확히 차감 - 소비 내역 올바르게 기록 ## 장점 - DB 스키마 변경 없음 - 기존 자동 선택과 호환 - 재고 부족 시 여러 로트 조합 가능 - 원가 최적화 가능 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
3.1 KiB
Python
81 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
테스트용 당귀 로트 추가 - 복합 로트 테스트를 위함
|
|
"""
|
|
import sqlite3
|
|
from datetime import datetime, timedelta
|
|
|
|
def add_test_lot():
|
|
conn = sqlite3.connect('database/kdrug.db')
|
|
cursor = conn.cursor()
|
|
|
|
try:
|
|
# 휴먼일당귀 herb_item_id 확인
|
|
cursor.execute("SELECT herb_item_id FROM herb_items WHERE herb_name = '휴먼일당귀'")
|
|
herb_item_id = cursor.fetchone()[0]
|
|
|
|
# 공급업체 ID 확인
|
|
cursor.execute("SELECT supplier_id FROM suppliers WHERE name = '한의사랑' LIMIT 1")
|
|
supplier_id = cursor.fetchone()[0]
|
|
|
|
# 기존 로트의 receipt_line_id 복사
|
|
cursor.execute("""
|
|
SELECT receipt_line_id
|
|
FROM inventory_lots
|
|
WHERE herb_item_id = ?
|
|
LIMIT 1
|
|
""", (herb_item_id,))
|
|
receipt_line_id = cursor.fetchone()[0]
|
|
|
|
# 새 로트 추가 (한국산, 다른 가격)
|
|
cursor.execute("""
|
|
INSERT INTO inventory_lots (
|
|
herb_item_id, supplier_id, receipt_line_id, received_date, origin_country,
|
|
unit_price_per_g, quantity_received, quantity_onhand,
|
|
expiry_date, lot_number, is_depleted, display_name
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
""", (
|
|
herb_item_id, # herb_item_id (휴먼일당귀)
|
|
supplier_id, # supplier_id
|
|
receipt_line_id, # receipt_line_id (기존 로트에서 복사)
|
|
datetime.now().strftime('%Y-%m-%d'), # received_date
|
|
'한국', # origin_country (기존은 중국)
|
|
18.5, # unit_price_per_g (기존은 12.9)
|
|
3000.0, # quantity_received
|
|
3000.0, # quantity_onhand
|
|
(datetime.now() + timedelta(days=365)).strftime('%Y-%m-%d'), # expiry_date
|
|
'TEST-DG-2024-001', # lot_number
|
|
0, # is_depleted
|
|
'일당귀(한국산)' # display_name
|
|
))
|
|
|
|
new_lot_id = cursor.lastrowid
|
|
|
|
conn.commit()
|
|
print(f"✅ 테스트용 당귀 로트 추가 완료!")
|
|
print(f" - Lot ID: {new_lot_id}")
|
|
print(f" - 약재: 휴먼일당귀")
|
|
print(f" - 원산지: 한국")
|
|
print(f" - 재고: 3000g")
|
|
print(f" - 단가: 18.5원/g")
|
|
|
|
# 현재 당귀 로트 현황 표시
|
|
print("\n=== 현재 휴먼일당귀 로트 현황 ===")
|
|
cursor.execute("""
|
|
SELECT lot_id, origin_country, quantity_onhand, unit_price_per_g
|
|
FROM inventory_lots
|
|
WHERE herb_item_id = ? AND is_depleted = 0
|
|
ORDER BY lot_id
|
|
""", (herb_item_id,))
|
|
|
|
for row in cursor.fetchall():
|
|
print(f"Lot #{row[0]}: {row[1]}산, 재고 {row[2]}g, 단가 {row[3]}원/g")
|
|
|
|
except Exception as e:
|
|
conn.rollback()
|
|
print(f"❌ 오류: {e}")
|
|
finally:
|
|
conn.close()
|
|
|
|
if __name__ == "__main__":
|
|
add_test_lot() |