feat: API에 variant 정보 추가

- 입고 상세 API에 display_name 및 variant 속성 추가
- 재고 상세 API에 lot_variants 테이블 조인
- 조제용 재고 조회 API에 display_name 포함

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
시골약사 2026-02-16 16:05:05 +00:00
parent a03f344635
commit 4d230a2ca8

57
app.py
View File

@ -813,17 +813,23 @@ def get_purchase_receipt_detail(receipt_id):
receipt_data = dict(receipt) receipt_data = dict(receipt)
# 입고장 상세 라인 조회 # 입고장 상세 라인 조회 (display_name 포함)
cursor.execute(""" cursor.execute("""
SELECT SELECT
prl.*, prl.*,
h.herb_name, h.herb_name,
h.insurance_code, h.insurance_code,
il.lot_id, il.lot_id,
il.quantity_onhand as current_stock il.quantity_onhand as current_stock,
il.display_name,
lv.form,
lv.processing,
lv.selection_state,
lv.grade
FROM purchase_receipt_lines prl FROM purchase_receipt_lines prl
JOIN herb_items h ON prl.herb_item_id = h.herb_item_id JOIN herb_items h ON prl.herb_item_id = h.herb_item_id
LEFT JOIN inventory_lots il ON prl.line_id = il.receipt_line_id LEFT JOIN inventory_lots il ON prl.line_id = il.receipt_line_id
LEFT JOIN lot_variants lv ON il.lot_id = lv.lot_id
WHERE prl.receipt_id = ? WHERE prl.receipt_id = ?
ORDER BY prl.line_id ORDER BY prl.line_id
""", (receipt_id,)) """, (receipt_id,))
@ -1402,20 +1408,26 @@ def get_available_lots(herb_item_id):
if not herb: if not herb:
return jsonify({'success': False, 'error': '약재를 찾을 수 없습니다'}), 404 return jsonify({'success': False, 'error': '약재를 찾을 수 없습니다'}), 404
# 가용 로트 목록 (소진되지 않은 재고) # 가용 로트 목록 (소진되지 않은 재고) - display_name 포함
cursor.execute(""" cursor.execute("""
SELECT SELECT
lot_id, il.lot_id,
origin_country, il.origin_country,
quantity_onhand, il.quantity_onhand,
unit_price_per_g, il.unit_price_per_g,
received_date, il.received_date,
supplier_id il.supplier_id,
FROM inventory_lots il.display_name,
WHERE herb_item_id = ? lv.form,
AND is_depleted = 0 lv.processing,
AND quantity_onhand > 0 lv.selection_state,
ORDER BY origin_country, unit_price_per_g, received_date lv.grade
FROM inventory_lots il
LEFT JOIN lot_variants lv ON il.lot_id = lv.lot_id
WHERE il.herb_item_id = ?
AND il.is_depleted = 0
AND il.quantity_onhand > 0
ORDER BY il.origin_country, il.unit_price_per_g, il.received_date
""", (herb_item_id,)) """, (herb_item_id,))
lots = [] lots = []
@ -1426,7 +1438,12 @@ def get_available_lots(herb_item_id):
'quantity_onhand': row[2], 'quantity_onhand': row[2],
'unit_price_per_g': row[3], 'unit_price_per_g': row[3],
'received_date': row[4], 'received_date': row[4],
'supplier_id': row[5] 'supplier_id': row[5],
'display_name': row[6],
'form': row[7],
'processing': row[8],
'selection_state': row[9],
'grade': row[10]
}) })
# 원산지별 요약 # 원산지별 요약
@ -1553,7 +1570,7 @@ def get_inventory_detail(herb_item_id):
herb_data = dict(herb) herb_data = dict(herb)
# 원산지별 재고 정보 # 원산지별 재고 정보 (display_name 포함)
cursor.execute(""" cursor.execute("""
SELECT SELECT
il.lot_id, il.lot_id,
@ -1563,9 +1580,15 @@ def get_inventory_detail(herb_item_id):
il.received_date, il.received_date,
il.supplier_id, il.supplier_id,
s.name as supplier_name, s.name as supplier_name,
il.quantity_onhand * il.unit_price_per_g as lot_value il.quantity_onhand * il.unit_price_per_g as lot_value,
il.display_name,
lv.form,
lv.processing,
lv.selection_state,
lv.grade
FROM inventory_lots il FROM inventory_lots il
LEFT JOIN suppliers s ON il.supplier_id = s.supplier_id LEFT JOIN suppliers s ON il.supplier_id = s.supplier_id
LEFT JOIN lot_variants lv ON il.lot_id = lv.lot_id
WHERE il.herb_item_id = ? AND il.is_depleted = 0 WHERE il.herb_item_id = ? AND il.is_depleted = 0
ORDER BY il.origin_country, il.unit_price_per_g, il.received_date ORDER BY il.origin_country, il.unit_price_per_g, il.received_date
""", (herb_item_id,)) """, (herb_item_id,))