fix: 규격 파싱 - T/C/P/D 수량 단위 우선, mg/ml 용량 단위 무시

- parse_spec 함수 개선: product_name에서도 수량 단위 추출
- 예: '스틸녹스정10mg(PTP) 14T' → spec='10mg'이어도 14T에서 14 추출
This commit is contained in:
thug0bin 2026-03-07 17:31:18 +09:00
parent 21c8124811
commit dc2a992c12
5 changed files with 70 additions and 7 deletions

6
backend/check_order.py Normal file
View File

@ -0,0 +1,6 @@
import requests
res = requests.get('http://localhost:7001/api/geoyoung/order-detail/DA2603-0255533', timeout=120)
data = res.json()
print('items:', len(data.get('items', [])))
for item in data.get('items', []):
print(f" {item.get('product_name')[:20]}: qty={item.get('quantity')}, order_qty={item.get('order_qty')}, amount={item.get('amount')}")

8
backend/check_spec.py Normal file
View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
import requests
geo = requests.get('http://localhost:7001/api/geoyoung/orders/summary-by-kd?start_date=2026-03-07&end_date=2026-03-07', timeout=120).json()
print("품목별 spec 필드 확인:")
for kd, info in geo.get('by_kd_code', {}).items():
print(f" spec='{info['spec']}' | {info['product_name'][:30]}")

19
backend/check_stilnox.py Normal file
View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import requests
# 지오영 확인
geo = requests.get('http://localhost:7001/api/geoyoung/orders/summary-by-kd?start_date=2026-03-07&end_date=2026-03-07', timeout=120).json()
print("=== 지오영 ===")
for kd, info in geo.get('by_kd_code', {}).items():
if '스틸' in info['product_name'] or '녹스' in info['product_name']:
print(f" {info['product_name']}: {info['boxes']}박스, {info['units']}")
# 수인 확인
sooin = requests.get('http://localhost:7001/api/sooin/orders/summary-by-kd?start_date=2026-03-07&end_date=2026-03-07', timeout=120).json()
print("\n=== 수인약품 ===")
for kd, info in sooin.get('by_kd_code', {}).items():
if '스틸' in info['product_name'] or '녹스' in info['product_name']:
print(f" {info['product_name']}: {info['boxes']}박스, {info['units']}")
if not any('스틸' in info['product_name'] for info in sooin.get('by_kd_code', {}).values()):
print(" (없음)")

9
backend/check_summary.py Normal file
View File

@ -0,0 +1,9 @@
import requests
res = requests.get('http://localhost:7001/api/geoyoung/orders/summary-by-kd?start_date=2026-03-07&end_date=2026-03-07', timeout=120)
data = res.json()
print('success:', data.get('success'))
print('order_count:', data.get('order_count'))
print('total_products:', data.get('total_products'))
print()
for kd, info in list(data.get('by_kd_code', {}).items()):
print(f"{kd}: boxes={info['boxes']}, units={info['units']}, {info['product_name'][:20]}")

View File

@ -596,12 +596,33 @@ def api_geoyoung_orders_by_kd():
start_date = request.args.get('start_date', today).strip()
end_date = request.args.get('end_date', today).strip()
def parse_spec(spec: str) -> int:
"""규격에서 수량 추출 (30T → 30, 100C → 100)"""
if not spec:
return 1
match = re.search(r'(\d+)', spec)
return int(match.group(1)) if match else 1
def parse_spec(spec: str, product_name: str = '') -> int:
"""
규격에서 수량 추출 (30T 30, 100C 100)
우선순위:
1. spec에서 T/C/P/D 단위 숫자 (: 14T 14)
2. product_name에서 T/C/P/D 단위 숫자
3. spec의 번째 숫자 (fallback)
"""
combined = f"{spec} {product_name}"
# T/C/P/D 단위가 붙은 숫자 우선 추출 (예: 14T, 100C, 30P, 140D)
qty_match = re.search(r'(\d+)\s*[TCPD]\b', combined, re.IGNORECASE)
if qty_match:
return int(qty_match.group(1))
# 없으면 spec의 첫 번째 숫자 (mg, ml 등 용량일 수 있음 - 기본값 1)
if spec:
num_match = re.search(r'(\d+)', spec)
if num_match:
val = int(num_match.group(1))
# mg, ml 같은 용량 단위면 수량 1로 처리
if re.search(r'\d+\s*(mg|ml|g)\b', spec, re.IGNORECASE):
return 1
return val
return 1
try:
session = get_geo_session()
@ -638,7 +659,7 @@ def api_geoyoung_orders_by_kd():
product_name = item.get('product_name', '')
spec = item.get('spec', '')
quantity = item.get('quantity', 0) or item.get('order_qty', 0)
per_unit = parse_spec(spec)
per_unit = parse_spec(spec, product_name)
total_units = quantity * per_unit
if kd_code not in kd_summary: