- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동 - 스크린샷을 screenshots/ 폴더로 이동 - 백업 파일 보존 (.backup) - 처방 관련 추가 스크립트 포함 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
API를 통한 Excel 입고 처리 테스트
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
# API 베이스 URL
|
|
BASE_URL = "http://localhost:5001"
|
|
|
|
def test_upload_excel():
|
|
"""Excel 업로드 테스트"""
|
|
|
|
# 1. 도매상 목록 확인
|
|
print("=== 도매상 목록 확인 ===")
|
|
response = requests.get(f"{BASE_URL}/api/suppliers")
|
|
suppliers = response.json()
|
|
|
|
if suppliers['success'] and suppliers['data']:
|
|
print(f"✓ 도매상 {len(suppliers['data'])}개 조회")
|
|
supplier_id = suppliers['data'][0]['supplier_id']
|
|
supplier_name = suppliers['data'][0]['name']
|
|
print(f"✓ 선택된 도매상: {supplier_name} (ID: {supplier_id})")
|
|
else:
|
|
print("도매상이 없습니다. 새로 생성합니다.")
|
|
# 도매상 생성
|
|
supplier_data = {
|
|
'name': '한의정보',
|
|
'business_no': '123-45-67890',
|
|
'contact_person': '담당자',
|
|
'phone': '02-1234-5678'
|
|
}
|
|
response = requests.post(f"{BASE_URL}/api/suppliers", json=supplier_data)
|
|
result = response.json()
|
|
if result['success']:
|
|
supplier_id = result['supplier_id']
|
|
print(f"✓ 도매상 생성 완료 (ID: {supplier_id})")
|
|
else:
|
|
print(f"✗ 도매상 생성 실패: {result.get('error')}")
|
|
return
|
|
|
|
# 2. Excel 파일 업로드
|
|
print("\n=== Excel 파일 업로드 ===")
|
|
|
|
# 파일 열기
|
|
file_path = 'sample/한의정보.xlsx'
|
|
with open(file_path, 'rb') as f:
|
|
files = {'file': ('한의정보.xlsx', f, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')}
|
|
data = {'supplier_id': supplier_id}
|
|
|
|
# 업로드
|
|
response = requests.post(f"{BASE_URL}/api/upload/purchase", files=files, data=data)
|
|
|
|
# 결과 확인
|
|
result = response.json()
|
|
if result['success']:
|
|
print(f"✓ 업로드 성공!")
|
|
print(f" - 형식: {result['summary']['format']}")
|
|
print(f" - 처리된 행: {result['summary']['processed_rows']}")
|
|
if 'processed_items' in result['summary']:
|
|
print(f" - 처리된 품목: {result['summary']['processed_items']}")
|
|
if 'total_amount' in result['summary']:
|
|
total = result['summary']['total_amount']
|
|
if isinstance(total, (int, float)):
|
|
print(f" - 총액: {total:,.0f}원")
|
|
else:
|
|
print(f" - 총액: {total}원")
|
|
else:
|
|
print(f"✗ 업로드 실패: {result.get('error')}")
|
|
|
|
# 3. 입고된 herb_items 확인
|
|
print("\n=== 입고된 herb_items 확인 ===")
|
|
response = requests.get(f"{BASE_URL}/api/herbs")
|
|
herbs = response.json()
|
|
|
|
if herbs['success']:
|
|
print(f"✓ 총 {len(herbs['data'])}개 herb_items")
|
|
# 샘플 출력
|
|
for herb in herbs['data'][:5]:
|
|
print(f" - {herb['herb_name']}: 보험코드={herb.get('insurance_code', 'N/A')}, 재고={herb.get('stock_quantity', 0):,.0f}g")
|
|
|
|
# 4. 재고 현황 확인
|
|
print("\n=== 재고 현황 확인 ===")
|
|
response = requests.get(f"{BASE_URL}/api/inventory/summary")
|
|
inventory = response.json()
|
|
|
|
if inventory['success']:
|
|
summary = inventory['data']
|
|
print(f"✓ 재고 요약:")
|
|
print(f" - 총 품목: {summary['total_items']}개")
|
|
print(f" - 재고 있는 품목: {summary['items_with_stock']}개")
|
|
print(f" - 총 재고 가치: {summary['total_value']:,.0f}원")
|
|
|
|
if __name__ == "__main__":
|
|
test_upload_excel() |