feat(order): 지오영 선별 주문 구현 완료
- full_order(auto_confirm=False)로 장바구니에 담기 - internal_code 사용 (product_code 아님) - submit_order_selective()로 선별 주문 - 기존 장바구니 품목 보존, 복원 완료
This commit is contained in:
parent
ad58cde952
commit
268f5bce8f
@ -281,25 +281,28 @@ def submit_geoyoung_order(order: dict, dry_run: bool, cart_only: bool = True) ->
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# ─────────────────────────────────────────
|
# ─────────────────────────────────────────
|
||||||
# 실제 주문 (빠른 API - ~1초/품목)
|
# 실제 주문 (선별 주문 - 기존 장바구니 보존)
|
||||||
# ─────────────────────────────────────────
|
# ─────────────────────────────────────────
|
||||||
from geoyoung_api import get_geo_session
|
from geoyoung_api import get_geo_session
|
||||||
|
|
||||||
geo_session = get_geo_session()
|
geo_session = get_geo_session()
|
||||||
|
|
||||||
# 1단계: 모든 품목을 장바구니에만 담기 (auto_confirm=False)
|
# 1단계: 모든 품목을 장바구니에 담기 (full_order, auto_confirm=False)
|
||||||
for item in items:
|
for item in items:
|
||||||
kd_code = item.get('kd_code') or item.get('drug_code')
|
kd_code = item.get('kd_code') or item.get('drug_code')
|
||||||
order_qty = item['order_qty']
|
order_qty = item['order_qty']
|
||||||
spec = item.get('specification', '')
|
spec = item.get('specification', '')
|
||||||
|
result = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 장바구니에만 담기 (주문 확정은 나중에 한번에)
|
# 장바구니에만 담기 (주문 확정은 나중에 한번에)
|
||||||
result = geo_session.quick_order(
|
result = geo_session.full_order(
|
||||||
kd_code=kd_code,
|
kd_code=kd_code,
|
||||||
quantity=order_qty,
|
quantity=order_qty,
|
||||||
spec=spec if spec else None,
|
specification=spec if spec else None,
|
||||||
check_stock=True
|
check_stock=True,
|
||||||
|
auto_confirm=False, # 장바구니만!
|
||||||
|
memo=f"자동주문 - {item.get('product_name', '')}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if result.get('success'):
|
if result.get('success'):
|
||||||
@ -318,12 +321,11 @@ def submit_geoyoung_order(order: dict, dry_run: bool, cart_only: bool = True) ->
|
|||||||
result_code = 'ERROR'
|
result_code = 'ERROR'
|
||||||
result_message = str(e)
|
result_message = str(e)
|
||||||
failed_count += 1
|
failed_count += 1
|
||||||
result = {}
|
|
||||||
|
|
||||||
update_item_result(item['id'], status, result_code, result_message)
|
update_item_result(item['id'], status, result_code, result_message)
|
||||||
|
|
||||||
# quick_order 결과에서 product_code 가져오기
|
# full_order 결과에서 internal_code 가져오기 (지오영은 internal_code 사용!)
|
||||||
product_code = result.get('product', {}).get('product_code') if result.get('success') else None
|
internal_code = result.get('product', {}).get('internal_code') if result.get('success') else None
|
||||||
|
|
||||||
# AI 학습용 컨텍스트 저장
|
# AI 학습용 컨텍스트 저장
|
||||||
save_order_context(item['id'], {
|
save_order_context(item['id'], {
|
||||||
@ -335,7 +337,7 @@ def submit_geoyoung_order(order: dict, dry_run: bool, cart_only: bool = True) ->
|
|||||||
'ordered_qty': order_qty,
|
'ordered_qty': order_qty,
|
||||||
'selection_reason': 'user_order',
|
'selection_reason': 'user_order',
|
||||||
'wholesaler_id': 'geoyoung',
|
'wholesaler_id': 'geoyoung',
|
||||||
'product_code': product_code
|
'internal_code': internal_code
|
||||||
})
|
})
|
||||||
|
|
||||||
results.append({
|
results.append({
|
||||||
@ -347,15 +349,15 @@ def submit_geoyoung_order(order: dict, dry_run: bool, cart_only: bool = True) ->
|
|||||||
'status': status,
|
'status': status,
|
||||||
'result_code': result_code,
|
'result_code': result_code,
|
||||||
'result_message': result_message,
|
'result_message': result_message,
|
||||||
'product_code': product_code # 선별 주문용
|
'internal_code': internal_code # 선별 주문용
|
||||||
})
|
})
|
||||||
|
|
||||||
# 2단계: cart_only=False면 선별 주문 (기존 품목 보존)
|
# 2단계: cart_only=False면 선별 주문 (기존 품목 보존)
|
||||||
if not cart_only and success_count > 0:
|
if not cart_only and success_count > 0:
|
||||||
try:
|
try:
|
||||||
# 이번에 담은 품목의 product_code만 수집
|
# 이번에 담은 품목의 internal_code만 수집
|
||||||
ordered_codes = [r['product_code'] for r in results
|
ordered_codes = [r['internal_code'] for r in results
|
||||||
if r['status'] == 'success' and r.get('product_code')]
|
if r['status'] == 'success' and r.get('internal_code')]
|
||||||
|
|
||||||
if ordered_codes:
|
if ordered_codes:
|
||||||
# 선별 주문: 기존 품목은 건드리지 않고, 이번에 담은 것만 주문
|
# 선별 주문: 기존 품목은 건드리지 않고, 이번에 담은 것만 주문
|
||||||
@ -375,7 +377,7 @@ def submit_geoyoung_order(order: dict, dry_run: bool, cart_only: bool = True) ->
|
|||||||
f'지오영 장바구니 담김, 확정 실패: {confirm_result.get("error", "알 수 없는 오류")}')
|
f'지오영 장바구니 담김, 확정 실패: {confirm_result.get("error", "알 수 없는 오류")}')
|
||||||
else:
|
else:
|
||||||
update_order_status(order_id, 'partial',
|
update_order_status(order_id, 'partial',
|
||||||
f'지오영 장바구니 담김, product_code 없음')
|
f'지오영 장바구니 담김, internal_code 없음')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"지오영 주문 확정 오류: {e}")
|
logger.error(f"지오영 주문 확정 오류: {e}")
|
||||||
update_order_status(order_id, 'partial',
|
update_order_status(order_id, 'partial',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user