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

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: