fix: 제품 선택 드롭다운에서 마스터 약재명 표시
- /api/herbs/by-ingredient API에서 마스터 약재명(herb_masters) 조회 추가 - 제품별 개별명(신흥인삼) 대신 통일된 성분명(인삼) 표시 - product_name 필드에 원래 제품명 보존, herb_name에 마스터명 제공 - 프론트엔드에서 약재명 [회사명] (재고) 형식으로 표시 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8d03e85648
commit
0bf0772864
20
app.py
20
app.py
@ -261,11 +261,21 @@ def get_herbs_by_ingredient(ingredient_code):
|
|||||||
try:
|
try:
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# 먼저 마스터 약재명 조회
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT herb_name
|
||||||
|
FROM herb_masters
|
||||||
|
WHERE ingredient_code = ?
|
||||||
|
""", (ingredient_code,))
|
||||||
|
master_row = cursor.fetchone()
|
||||||
|
master_herb_name = master_row[0] if master_row else None
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT
|
SELECT
|
||||||
h.herb_item_id,
|
h.herb_item_id,
|
||||||
h.insurance_code,
|
h.insurance_code,
|
||||||
h.herb_name,
|
h.herb_name as product_name,
|
||||||
h.specification,
|
h.specification,
|
||||||
CASE
|
CASE
|
||||||
WHEN h.specification LIKE '%신흥%' THEN '신흥'
|
WHEN h.specification LIKE '%신흥%' THEN '신흥'
|
||||||
@ -286,7 +296,13 @@ def get_herbs_by_ingredient(ingredient_code):
|
|||||||
ORDER BY stock_quantity DESC, h.herb_name
|
ORDER BY stock_quantity DESC, h.herb_name
|
||||||
""", (ingredient_code,))
|
""", (ingredient_code,))
|
||||||
|
|
||||||
products = [dict(row) for row in cursor.fetchall()]
|
products = []
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
product = dict(row)
|
||||||
|
# 마스터 약재명 추가
|
||||||
|
product['herb_name'] = master_herb_name or product['product_name']
|
||||||
|
products.append(product)
|
||||||
|
|
||||||
return jsonify({'success': True, 'data': products})
|
return jsonify({'success': True, 'data': products})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'error': str(e)}), 500
|
return jsonify({'success': False, 'error': str(e)}), 500
|
||||||
|
|||||||
@ -1674,7 +1674,8 @@ $(document).ready(function() {
|
|||||||
productSelect.append('<option value="">제품 선택</option>');
|
productSelect.append('<option value="">제품 선택</option>');
|
||||||
response.data.forEach(product => {
|
response.data.forEach(product => {
|
||||||
const stockInfo = product.stock_quantity > 0 ? `(재고: ${product.stock_quantity.toFixed(1)}g)` : '(재고 없음)';
|
const stockInfo = product.stock_quantity > 0 ? `(재고: ${product.stock_quantity.toFixed(1)}g)` : '(재고 없음)';
|
||||||
productSelect.append(`<option value="${product.herb_item_id}" ${product.stock_quantity === 0 ? 'disabled' : ''}>${product.company_name} ${stockInfo}</option>`);
|
const companyInfo = product.company_name ? `[${product.company_name}]` : '';
|
||||||
|
productSelect.append(`<option value="${product.herb_item_id}" ${product.stock_quantity === 0 ? 'disabled' : ''}>${product.herb_name} ${companyInfo} ${stockInfo}</option>`);
|
||||||
});
|
});
|
||||||
productSelect.prop('disabled', false);
|
productSelect.prop('disabled', false);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user